1

[![enter image description here][1]][1]enter image description hereFilename : productScreen.js

Error : line 6 - TypeError: Object(...) is not a function

Path :src/Screens/ProductScreen.js

Code as follows:

  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|    } , [])

Filename : store.js

Path : src/store.js

Code as follows:

    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;

Filename : index.js

Path :src/index.js

Code as follows:

    ReactDOM.render(
    <Provider store = {store}>
    <App />
    </Provider>,
    document.getElementById('root')
    );
    serviceWorker.unregister();

All imports are made correctly

4
  • Can you recreate the issue on codesandbox.io? What you shared seems ok Commented May 31, 2020 at 6:57
  • How are you importing useSelector? Please include the missing lines 1 and 2 in your ProductScreen component. See example usages from React Redux docs. Commented May 31, 2020 at 14:23
  • added the image, please check. Commented May 31, 2020 at 14:36
  • You seem to have imported useSelector from react-dom. You need to import it from react-redux library Commented May 31, 2020 at 14:45

1 Answer 1

1

It seems that you're missing useSelector import statement.

Add import { useSelector } from "react-redux"; in your ProductScreen.js file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.