score:1

Accepted answer

i added init to your store:

// @datareducer.js
export const initialdatastate = {
  init: true,
  posts: []
};

const datareducer = (state, action) => {
  switch (action.type) {
    case 'all':
      // init false
      return { ...state, posts: action.payload };
    case 'inc':
      return { ...state, init: false, posts: [...state.posts, action.payload] };
...
}
// @app.js
function app() {
  const [{ init, posts }, dispatch] = useglobalstate();

  useeffect(() => {
    init ? getinc(dispatch) : getall(dispatch);
  }, [init, dispatch]);
...
}

edit funny-violet-pwew6


Related Query