Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda