Context provides a way to pass data through the component tree without having to pass props down manually at every level.
SWR
SWR is a popular library used for data fetching and state management in React applications. Data fetching is covered in section, here we are going to cover about state management using SWR.
Materially is managing state of following using SWR
Snackbar states
Menu states
1. Snackbar
Snackbar is used to show notification in application. Whenever component dispatch a action with data to show snackbar, it appears in app. The initial state of snackbar is being capture using useSWR hooks and after that, we are mutating it state based on action calls. Following is the initital state:
This values has been inititilised using useSWR like below:
To read the values and listen, following the SWR hooks is sufficient in the component. Whenever any changes happen, it is activated like a redux selector and acts based on logic.