[Question] Stateful shared component
See original GitHub issueI have a component that is reused across the application but it has a different state for each of its parents. Am i allowed to this? (currently working)
type Props = {
branchState: RecoilState<string>;
};
export default function Branches({ branchState }: Props) {
const [selectedBranch, selectBranch] = useRecoilState(branchState);
...
}
Would love your opinion.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Is it possible to share states between components using ...
We move React hooks stateful logic from HookComponent to useShareableState . We call useShareableState using useBetween in each component.
Read more >Stateless v/s Stateful Components in React - YouTube
react #StatefulvsStatelessHey Guys, welcome to my series where we will learn about commonly asked Interview Questions.
Read more >How To Share State Across React Components with Context
In this tutorial, you'll share state across multiple components using React context. React context is an interface for sharing information ...
Read more >Stateful and Stateless Components in React
Today, we're going to review what stateful and stateless components are in React, how you can tell the difference, and the complex process ......
Read more >React Hooks Are Great to Reuse Stateful Logic But What's The ...
Summary. React Hooks is an excellent solution for sharing component stateful logic. However, when it comes to sharing stateful logic by Stateful Component...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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. The current selected is what i want to not be shared so each view has different state but the api call for branches is common so only 1 request is ever sent.