Next.js Discord

Discord Forum

redux store not found in a component

Unanswered
Mucuchies posted this in #help-forum
Open in Discord
MucuchiesOP
Hey there, i'm having issue to work with redux. I'm on Next using the app router. One of my page has this error: "could not find react-redux context value; please ensure the component is wrapped in a <Provider>"

Here is my folder:

--app
  page.js
  layout.js
  /movies/[movies]/
    page.js
-- store
  store.js


I've wrap the content of my app in the layout with a provider like this:

"use client";
import { Provider } from "react-redux";
import { store } from "./store";

export default function ReduxProvider({ children }) {
  return <Provider store={store}>{children}</Provider>;
}


on my main page i'm dispatching then navigation to my custom page that will have to select the content of my store:

/app/page.js
const PopularMovies = () => {
 const dispatch = useDispatch();

 const goToMovieDetails = (movie) => {
    dispatch(setSelectedMovie(movie));
    router.push(`/movies/${movie.id}`);
  };
return (
    <>
       ...
       <li onClick={() => goToMovieDetails(movie)}></li>
    </>
  );
};


Onclick we are navigating to that component, and when i'm on it, the error pops:

/[movies]/movies/page.js
// MovieDetails.js
import { useSelector } from "react-redux";

const MovieDetails = () => {
  const selectedMovie = useSelector((state) => state.selected_movie);
  const { title, release_date, overview, backdrop_path } = selectedMovie;
  return (
    <div>...</div>
  );
};

1 Reply

Golden northern bumble bee
@Mucuchies wrap root laout componet with reduxProvide or you can simply import provider and store in root layout directly and check store configuration and slices in store ..what error you are getting