TypeError: Object(...) is not a function React.js
TypeError: Object(...) is not a function React.js
[![在此处输入图像描述][1]][1]文件名:productScreen.js
错误:第 6 行 - 类型错误:对象 (...) 不是函数
路径: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();
所有导入都正确
您似乎缺少 useSelector
导入语句。
在您的 ProductScreen.js
文件中添加 import { useSelector } from "react-redux";
。
[![在此处输入图像描述][1]][1]
错误:第 6 行 - 类型错误:对象 (...) 不是函数
路径: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();
所有导入都正确
您似乎缺少 useSelector
导入语句。
在您的 ProductScreen.js
文件中添加 import { useSelector } from "react-redux";
。