Multiple stores

Handling multiple stores in a React-Redux application

In a react-redux application, it is a good practice to have only one redux store. But if for some weird/“special” reason if you have to have more than one store, you will face some problems. The most common problem is that if we wrap a component with a provider and then wrap a child component with another provider, it’s not easy to subscribe to the store of top-level provider. const Component1 = () => { return ( <Provider store={store1}> <Provider store={store2}> <Component2 /> </Provider> </Provider> ); }; It’s so confusing that within a few iterations of development, you’ll find yourself using providers on each component, and not being able to read values from both the stores in a single component will frustrate you....

October 12, 2021 · 2 min · Vikas Kumar
useEffect vs direct Function Call

Difference between 'useEffect' and calling function directly inside a component.

In React, the useEffect hook is pretty straightforward. But its simplicity sometimes makes me forget its actual function. I remembered useEffect simply as something which takes a callback and a dependency array as arguments, and it will execute the callback whenever the dependency array is changed. And in case of no dependency array, it will run the callback each time the component renders. But then what will be the difference between the following two cases....

May 9, 2021 · 3 min · Vikas Kumar
OneSignal ReactJs

How to use OneSignal with ReactJs

Using OneSignal with react is fairly easy if one doesn’t care about existing service-worker. But if there is an existing service worker, things may not work as is expected. First, we will create a react app with a service-worker. npx create-react-app my-app --template pwa This should create a folder named 'my-app' containing all the app-related files. To check everything is fine, we can run the following commands, and a browser tab should open with the ReactJs logo....

January 9, 2021 · 3 min · Vikas Kumar