Answer the question
In order to leave comments, you need to log in
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
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
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
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 questionAsk a Question
731 491 924 answers to any question