TypeError:Object(...)不是React.js函数

时间:2020-05-31 06:41:25

标签: javascript reactjs react-redux react-props react-state

[![在此处输入图片描述] [1]] [1] enter image description here 文件名: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();

所有导入均正确完成

1 个答案:

答案 0 :(得分:1)

似乎您缺少useSelector导入语句。

import { useSelector } from "react-redux";文件中添加ProductScreen.js