I
I
InterestingPerson2015-11-06 13:42:30
React
InterestingPerson, 2015-11-06 13:42:30

When should you use props and when should you use state?

When should you use props and when should you use state?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey, 2015-11-06
@Murmurianez

read-only props - parameters passed from <MyElement param1={param1} param2={param2} />
state the current state of the element, which we can overwrite at any time inside the element

R
Ruslan Abdullaev, 2015-11-06
@rajdee

State is the internal mutable state of the component, props is the external "immutable" data that is passed through the parent
"immutable" is more of a wish than an axiom

N
Nikita Gushchin, 2015-11-06
@iNikNik

When to use state
In short, most of your components are stateless. There is a controller-view pattern: you usually have a few controller components at the top levels of the tree that have their own state, and the rest of the components just accept props and render them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question