I have these two reducers
const getPosts = (initialState = {posts: []}, action) => {...}
const createPost = (initialState = {post: null}, action) => {...}
where getPosts
reducer puts the fetched posts performed by the associated action creator in the state variable posts
, while createPost
puts the created post in the state variable post
. The action creator associated with the createPost
stores the post into the database in the backend, and after storing the post in the database, I would like to update the posts on the page in the frontend from getPosts
without fetching all the posts again from the database again because I already have all the posts in the state but the new one. So, what I am trying to do is to push the created post into the posts
state variable, but both states are in different reducers. How can I push the post
state variable's value into the posts
state variable to achieve an update at the frontend without fetching all the posts again after each post creation?
question from:
https://stackoverflow.com/questions/65923632/share-states-between-two-reducers-react-redux 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…