import React from 'react'; import ReactDOM from 'react-dom'; import Map from './components/map/container/map'; import App from './App'; import './index.css'; import shell from './shared/utility/shell'; import { render } from 'react-dom' import { Provider } from 'react-redux' import { createStore, applyMiddleware, compose } from 'redux' import { routerMiddleware, ConnectedRouter } from 'react-router-redux' import thunk from 'redux-thunk' import createHistory from 'history/createBrowserHistory' import rootReducer from './reducers' import registerServiceWorker from './registerServiceWorker'; import { Routes } from './config'; const history = createHistory(); const target = document.querySelector('#root') const initialState = {}; const enhancers = []; const middleware = [ thunk, routerMiddleware(history) ]; if (process.env.NODE_ENV === 'development') { const devToolsExtension = window.devToolsExtension; if (typeof devToolsExtension === 'function') { enhancers.push(devToolsExtension()); } } const composedEnhancers = compose( applyMiddleware(...middleware), ...enhancers ); const store = createStore( rootReducer, initialState, composedEnhancers ); render( <Provider store={store}> <ConnectedRouter history={history}> <div> <Routes /> </div> </ConnectedRouter> </Provider>, target ) registerServiceWorker(); ReactDOM.render(<App />, document.getElementById('root')); registerServiceWorker();
I am trying to call an API from with the help of redux and display its data in a table. I am getting this error. Above is my index.js
file.
1. Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.
2. React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.
I have referred to many answers I am not able to recognize the error.
To solve the error "Element type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got", make sure to import named exports using curly braces and default exports without, and only use functions or classes as components.
You can pass a component as props in React by using the built-in children prop. All elements you pass between the opening and closing tags of a component get assigned to the children prop.
React. cloneElement() is part of the React Top-Level API used to manipulate elements. It clones and returns a new element using its first argument as the starting point. This argument can be a React element or a component that renders a React element.
React. createElement( type, [props], [... children] ) Create and return a new React element of the given type. The type argument can be either a tag name string (such as 'div' or 'span' ), a React component type (a class or a function), or a React fragment type.
Problem is in the import statements. You have not used curly braces while importing some components like createHistory
.
If a component uses a default export like:
export default X
Then you can simply import it like:
import X from './X';
But if you are using a named export like:
export const X=1;
Then you need to import it in curly braces like:
import {X} from './X';
So have a look at your imports. This will resolve your issue.
I ran into the same problem in my react application. It's definitely your import statements as stated above. I changed:
import {x} from '/x.js'
to import x from '/x.js'
and that got the job done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With