[ad_1]
Hello
I have recently changed my implementation to include react router on my wordpress site. So I made changes to react index.js. Now when I am trying to render I keep on getting this
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.Here areis my index.js
import {HomePageFlightContainer} from './HomePageFlightContainer';
import {PageFetch} from './PageFetch';
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
export const App = () => {
return (
<Router >
<Switch>
<Route path="/wordpress/search" component={PageFetch} />
<Route path="/" component={HomePageFlightContainer} />
</Switch>
</Router>
);
};
ReactDOM.render(<App />, document.getElementById('search-flights-container')); functions.php
wp_enqueue_script('theme', get_stylesheet_directory_uri() . '/dist/js/bundle.js', ['wp-element'], '1.0', true);
wp_enqueue_script('FlighContainerBundle', get_stylesheet_directory_uri() . '/dist/js/FlighContainerBundle.js', ['wp-element'], '1.0', true)Webpack.config.js is
const path = require('path');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpackConfig = {
mode: 'development',
entry: {
bundle: path.join(__dirname, 'src', 'index.js'),
FlighContainerBundle: path.join(__dirname, 'src', 'FlighContainer.js')
},
output: {
filename: 'js/[name].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
....As per several suggestions given on stackoverflow , like this –
https://stackoverflow.com/questions/34130539/uncaught-error-invariant-violation-element-type-is-invalid-expected-a-string
I have changed all components to use react named export/imports but I still get that above mentioned error
Can anyone please help?
