You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks a lot for the great work. Am really learning a lot from the lecture but got hooked up in part 12 "adding Redux to details" I triied modifying the index.js file as intructed with "Provider'" in the lesson but keep getting this error message (section of video: 13.20)
"Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of Context.Consumer."
See my code below
import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from "react-redux";
import './index.css';
import App from './App';
import store from "./store"
I don't know were the error is from. Please kindly assist.
See code from the following;
(1)
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from "react-redux";
import './index.css';
import App from './App';
import store from "./store"
ReactDOM.render(
,
document.getElementById('root'));
(2)
App.js
import express from "express";
import data from "./data.js";
Thanks a lot for the great work. Am really learning a lot from the lecture but got hooked up in part 12 "adding Redux to details" I triied modifying the index.js file as intructed with "Provider'" in the lesson but keep getting this error message (section of video: 13.20)
"Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of Context.Consumer."
See my code below
import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from "react-redux";
import './index.css';
import App from './App';
import store from "./store"
ReactDOM.render(
,
document.getElementById('root'));
I don't know were the error is from. Please kindly assist.
See code from the following;
(1)
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from "react-redux";
import './index.css';
import App from './App';
import store from "./store"
ReactDOM.render(
,
document.getElementById('root'));
(2)
App.js
import express from "express";
import data from "./data.js";
const app = express();
app.get("/api/products/:id", (req, res) => {
const productId = req.params.id;
const product = data.products.find(x=>x.id === productId);
if(product)
res.send(product);
else
res.status(404).send({ msg: "Prodcut not Found"})
});
app.get("/api/products", (req, res) => {
res.send(data.products);
});
app.listen(5000, () => { console.log("Server started at http://localhost:5000") });
(3)
ProductActions.js
import { PRODUCT_LIST_REQUEST, PRODUCT_LIST_SUCCESS, PRODUCT_LIST_FAIL, PRODUCT_DETAILS_REQUEST,
PRODUCT_DETAILS_SUCCESS, PRODUCT_DETAILS_FAIL } from "../constants/productConstants";
import axios from "axios";
const listProducts = () => async (dispatch) => {
}
const detailsProduct = (productId) => async (dispatch) => {
try{
dispatch({type: PRODUCT_DETAILS_REQUEST, payload: productId});
const {data} = await axios.get("/api/products/" + productId);
dispatch({type: PRODUCT_DETAILS_SUCCESS, payload: data });
} catch (error) {
dispatch({type: PRODUCT_DETAILS_FAIL, payload: error.message});
}
}
export { listProducts, detailsProduct }
(4)
store.js
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import { productListReducer, productDetailsReducer } from './reducers/productReducers';
import thunk from "redux-thunk";
const initialState= {};
const reducer = combineReducers({
productList: productListReducer,
productDetails: productDetailsReducer,
})
const composeEnhancer = window.REDUX_DEVTOOLS_EXTENSION_COMPOSE || compose;
const store = createStore(
reducer,
initialState,
composeEnhancer(applyMiddleware(thunk))
);
export default store;
(5)
productScreen.js
import React, { useEffect } from "react";
import {Link} from "react-router-dom"
import { useSelector, useDispatch } from "react-redux";
import { detailsProduct } from "../actions/productActions"
function ProductScreen(props){
const productDetails = useSelector(state => state.productDetails);
useEffect(() => {
dispatch(detailsProduct(props.match.params.id));
return () => {
//
};
}, [dispatch])
}
export default { ProductScreen, detailsProduct}
(6)
HomeScreen.js
import React, { useState, useEffect } from "react";
import {Link} from "react-router-dom"
import axios from "axios"
import { useSelector, useDispatch } from "react-redux";
import {listProducts} from "../actions/productActions";
function HomeScreen(props){
}
export default HomeScreen;
(7)
productConstants.js
export const PRODUCT_LIST_REQUEST = "PRODUCT_LIST_REQUEST";
export const PRODUCT_LIST_SUCCESS = "PRODUCT_LIST_SUCCESS";
export const PRODUCT_LIST_FAIL = "PRODUCT_LIST_FAIL";
export const PRODUCT_DETAILS_REQUEST = "PRODUCT_DETAILS_REQUEST";
export const PRODUCT_DETAILS_SUCCESS = "PRODUCT_DETAILS_SUCCESS";
export const PRODUCT_DETAILS_FAIL = "PRODUCT_DETAILS_FAIL";
(8)
productsReducers.js
import { PRODUCT_LIST_REQUEST, PRODUCT_LIST_FAIL, PRODUCT_LIST_SUCCESS, PRODUCT_DETAILS_REQUEST, PRODUCT_DETAILS_SUCCESS, PRODUCT_DETAILS_FAIL } from "../constants/productConstants";
function productListReducer (state = {products: []}, action) {
};
function productDetailsReducer (state = {product: {}}, action) {
}
export {productListReducer, productDetailsReducer}
The text was updated successfully, but these errors were encountered: