[![在此处输入图片描述] [1]] [1] 文件名:productScreen.js
错误:第6行-TypeError:Object(...)不是函数
路径:src / Screens / ProductScreen.js
代码如下:
3 | import { Link } from "react-router-dom";
4 | import { detailsProduct } from "../actions/productActions";
5 | function ProductScreen(props){
>6| const productDetails= useSelector(state => state.productDetails);
7 | const {product , loading , error} = productDetails;
8 | const dispatch = useDispatch();
9 | useEffect(()=>{
10| dispatch(detailsProduct(props.match.params.id));
11| return () => {
12| };
13| } , [])
文件名:store.js
路径:src / store.js
代码如下:
1|const initialState = {}
2|const reducer = combineReducers({
3|productList: productListReducer,
4|productDetails: productDetailsReducer
5| })
6|const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
7|const store = createStore(reducer , initialState , composeEnhancer(applyMiddleware(thunk)));
8|export default store;
文件名:index.js
路径:src / index.js
代码如下:
ReactDOM.render(
<Provider store = {store}>
<App />
</Provider>,
document.getElementById('root')
);
serviceWorker.unregister();
所有导入均正确完成
答案 0 :(得分:1)
似乎您缺少useSelector
导入语句。
在import { useSelector } from "react-redux";
文件中添加ProductScreen.js
。