D
D
dron1122021-08-29 14:09:35
React
dron112, 2021-08-29 14:09:35

How to combine next.js and redux?

Next.js has a getServerSideProps function that can return data from the server as props to the component.
But what if I need this data not only in the component, but also in redux?

export default function RoomsPage({dataUsers}) {
  const dispatch = useDispatch()

  React.useEffect(() => {
    dispatch(userActions.setUser(dataUsers))
  }, [dataUsers])

  const users = useSelector((state: any) => state?.users)
.....


Can it be done like this:
  1. Get data into component from getServerSideProps
  2. in useEffect send them to redux
  3. On the next line in useSelector get the same data from redux
  4. and render them in markup

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question