Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
Keep previous page state in redux toolkit

I'm going to implement a product page where it contents similar products when I hit on similar product component it should open same screen component and keep previous product screen in navigation history.

Can anybody help me please?

productSlice.js

const productSlice = createSlice({
  name: "product",
  initialState: {
    product: null,
    loading: false,
  },
  reducers: {
    getProductStart: (state) => {
      state.loading = true;
    },
    getProductSuccess: (state, { payload }) => {
      state.product = payload;
      state.loading = false;
    },
    getProductFailure: (state, { payload }) => {
      state.loading = false;
    },
  },
});

const { actions, reducer } = productSlice;
export const productSelector = (state) => state.product;

export default reducer;

export function fetchProduct(id){
    return dispatch => {
        ...
    }
}

store.js

const reducers = combineReducers({
  product: productReducer,
});

const store = configureStore({
  reducer: reducers,
});

export default store;

ProductScreen.js

function ProductScreen({ navigation, route }) {
  const dispatch = useDispatch();
  const { product, loading } = useSelector(productSelector);

  useEffect(() => {
    dispatch(fetchProduct(route.params.id));
  });

  const openSimilarProduct = (id) => {
      navigation.push("ProductScreen", { id });
  }

  return (
    <View>
      <Text>{product.name}</Text>
      <Text>{product.description}</Text>

      <View>
          <Pressable onPress={() => openSimilarProduct(1)} >
            <Text>Product #1</Text>
          </Pressable>
      </View>
    </View>
  );
}

export default ProductScreen;
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

The common pattern in e-commerce appication is fetch product information then fetch similar products and list them in form of grids on bottom.

At high level, you need to fetch product information and by using product metadata like type or category you can fetch other product with that similar attribute. User don't need to press button for fetch those similar products.

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda