0

I am using next13. I heard that in next13 all files are rendered server-side without the need to use the serversideProps function.

However, if you don't do "use Client", an error occurs. How can I import movies data by server-side rendering without using useEffect here? Also I am using redux-toolkit.

(Home.tsx)

  "use client";

  export default function Home() {
    const { movies } = useSelector((state: RootState) => state.post);

    const dispatch = useAppDispatch();

    useEffect(() => {
      const getmovie = async () => {
        dispatch(LoadMovies(API_KEY));
      };

      getmovie();
    }, []);

    return (
      <Container>
        <CardWrapper>
          {movies.map((v) => {
            return <Card movie={v} />;
          })}
        </CardWrapper>
      </Container>
    );
  }

(action.tsx)

  export const LoadMovies = createAsyncThunk(
    "post/LoadMovies",
    async (data: any, { rejectWithValue }) => {
      try {
        const response = await axios.get(
          `https://api.themoviedb.org/3/${"movie/top_rated"}?api_key=${data}&language=en-US&page=1`
          // { next: { revalidate: 10000 } }
        );
        console.log("response:", response);
        return response.data.results;
      } catch (error: any) {
        console.error(error);
        return rejectWithValue(error.response.data);
      }
    }
  );
Jonas
  • 121,568
  • 97
  • 310
  • 388
user19476497
  • 495
  • 1
  • 10
  • Hi, user19476497! Please go through the first linked thread to understand how to fetch data on the server in the app directory. And visit the second one to get a clear view of how and where you want to use client stores like Redux. – Youssouf Oumar May 18 '23 at 08:08

0 Answers0