Skip to content

Running useEffect in react 18: #11

Description

@fmanimashaun

I noticed the code below will not work in React 18 as the component renders twice during the initial rendering. in strict mode

 .addCase(fetchPosts.fulfilled, (state, action) => {
               state.status = 'succeeded'
               // Adding date and reactions
               let min = 1;
               const loadedPosts = action.payload.map(post => {
                   post.date = sub(new Date(), { minutes: min++ }).toISOString();
                   post.reactions = {
                       thumbsUp: 0,
                       wow: 0,
                       heart: 0,
                       rocket: 0,
                       coffee: 0
                   }
                   return post;
               });

               // Add any fetched posts to the array
               state.posts = state.posts.concat(loadedPosts)
           })

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions