我有一个react应用程序(没有重复),这个应用程序有一个购物车。购物车在App组件中的状态中定义,并在树的多个组件中传递和使用。ShoppingCart = ({ cart }) => { // not sure how to update cart and update state}
// not sure how to upda
> 40 | let { state, dispatch } = React.useContext(ContextOne); let [state, dispatch] = React.useReducer(reducer, initialState);
let value = { state, dispatch感谢soywood,下面是工作上下文提供程序代码: import * as R
代码: import React from 'react';import App from '.import {configureStore} from '@reduxjs/toolkit';function counterReducer(stateinitialState,action) {
if(ac