Search code examples
reactjsredux

Is it oaky to use React Context alongside with Redux Provider?


I am building a simple real time messaging app using react and socket.io for practice.

Current solution uses React's Context only to store socket.io object and React-Redux to store the rest.

The reason that I'm using the context alongside the redux is because redux cries for the following error when I try to store socket.io object into its state.

enter image description here

I also thought of using an exported socket.io module instead of the Context:

import io from "socket.io-client";

const socket = io(URL);

socket.connect();

export socket;

but did read some thread saying that it is not a great practice of using React ecosystem.

Any inputs, please?


Solution

  • It is absolutely fine to use Redux for state management and Context for dependency injection like you are doing here.

    That's exactly what each of these were made for.