[Question] Stateful shared component #970
-
I have a component that is reused across the application but it has a different state for each of its parents.
Would love your opinion. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
If I understand correctly, the question is whether you can pass an atom in as a prop. If so, yes, this is a great way to do things. |
Beta Was this translation helpful? Give feedback.
-
@davidmccabe, we should probably add this as a pattern in the docs somewhere.. Ideas on a good place for it? |
Beta Was this translation helpful? Give feedback.
-
If this doesnt cause unnecessary renders then, this is one of the best code reusability features. |
Beta Was this translation helpful? Give feedback.
-
Something else I'll do occasionally is make the prop optional and have the component define it's own internal atom. That way users of the component don't need to provide one if it's isolated. But, if they want to sync state with something else, then they can provide an atom override. |
Beta Was this translation helpful? Give feedback.
-
Ye its all depend on the use case. If u are ok about sharing the state in different routes/view s then it's great. For example in my case, branches has an async selector to get list of branches from server and has the current selected branch as an atom. |
Beta Was this translation helpful? Give feedback.
If I understand correctly, the question is whether you can pass an atom in as a prop. If so, yes, this is a great way to do things.