React.CreateElement issue on react-router-v4, not v4-alpha4 - reactjs

I'm trying to figure out why a specific function is working with the alpha version of React Router but not the current v4 version
index.js
import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter, Match } from 'react-router';
import NotFound from './components/NotFound';
const Root = () => {
return (
<BrowserRouter>
<div>
<Match exactly pattern="/" component={NotFound} />
</div>
</BrowserRouter>
)
}
render(<Root />, document.querySelector('#root'));
package.json
{
"name": "rbm-dashboard",
"version": "0.1.0",
"private": true,
"dependencies": {
"material-ui": "^0.17.0",
"react": "^15.4.2",
"react-tap-event-plugin": "^2.0.1",
"react-dom": "^15.4.2"
},
"devDependencies": {
"react-router": "4.0.0-alpha.4",
"react-scripts": "0.9.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
NotFound.js
import React from 'react';
class NotFound extends React.Component {
render() {
return (
<h2>Not Found</h2>
)
}
}
export default NotFound;
When i switch the react-router version from 4.0.0-alpha.4 to ^4.0.0, i get the following errors
I don't have an issue using the alpha version, however I would like to figure out what the issue is so i can learn from it. Also if needed i can push the code to github if anyone wants to look at it locally.
Thank you

Because Match isn't a thing anymore. Change Match pattern to Route path and you should be good. Also, import everything from react-router-dom not react-router.

Related

Algolia's searchBox is stuck and is not accepting new values

I'm trying to type new values ​​after instantiating Algolia's SearchBox, but it doesn't change the input value at all. I've recreated the NextJs boilerplate and implemented it 5 times, but the value never changes. What could it be?
In short: when I type something in the input, the value just doesn't update
Github:
https://github.com/Arthur-Maskalenkas/bug-report
sandbox:
https://codesandbox.io/p/github/Arthur-Maskalenkas/bug-report/csb-zf1foq/draft/happy-smoke?file=%2FREADME.md
my currently index.tsx is
import type { NextPage } from 'next'
import algoliasearch from 'algoliasearch/lite';
import {
InstantSearch,
SearchBox,
Pagination,
Configure,
} from 'react-instantsearch-dom';
const Home: NextPage = () => {
const searchClient = algoliasearch(
'B1G2GM9NG0',
'aadef574be1f9252bb48d4ea09b5cfe5'
);
return (
<div className="ais-InstantSearch">
<h1>React InstantSearch e-commerce demos</h1>
<InstantSearch searchClient={searchClient} indexName="demo_ecommerce">
<Configure hitsPerPage={8}/>
<div className="search-panel">
<div className="search-panel__filters">
</div>
<div className="search-panel__results">
<SearchBox
className="searchbox"
translations={{
placeholder: ''
}}
/>
<div className="pagination">
<Pagination/>
</div>
</div>
</div>
</InstantSearch>
</div>
)
}
export default Home
my package
{
"name": "teste2",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"algoliasearch": "^4.14.2",
"next": "12.3.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-instantsearch-dom": "^6.33.0"
},
"devDependencies": {
"#types/node": "18.7.20",
"#types/react": "18.0.21",
"#types/react-dom": "18.0.6",
"#types/react-instantsearch-dom": "^6.12.3",
"eslint": "8.24.0",
"eslint-config-next": "12.3.1",
"typescript": "4.8.3"
}
}
There is a known issue with React 18.x strict mode and older InstantSearch libraries. The resolution is to set reactStrictMode: false in next.config.js (not recommended), downgrade to React 17, or move to the newer react-instantsearch-hooks library as documented here: https://github.com/algolia/react-instantsearch/issues/3634

React Router v6 and React.lazy not working correctly, throwing an error

Am refactoring my React application and have upgrade from React Router v5 to v6, seeing this error with a very simple React.lazy() call:
Error: Objects are not valid as a React child (found: object with keys {$$typeof, _payload, _init}).
If you meant to render a collection of children, use an array instead.
import React, { lazy } from 'react';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
const Pizzas = () => lazy(() => import('./Components/Pizzas'));
const App = () => {
return (
<div>
<Router>
<Routes>
<Route path="/" element={<Pizzas />} />
</Routes>
</Router>
</div>
);
};
export default App;
And the Pizzas component is just:
export const Pizzas = () => <div>Pizzas...</div>;
Now, if I change it over to this, it works just fine:
import { Pizzas } from './Components/Pizzas';
... And the component renders just fine. It's a bit of a strange one and I have been searching for solutions with React Router v6 for an hour or so now to no avail. I'm using Create React App as well for reference.
Dependencies (package.json)
{
"name": "project-name",
"dependencies": {
"#emotion/css": "^11.1.3",
"#testing-library/jest-dom": "^5.11.9",
"#testing-library/react": "^11.2.5",
"#testing-library/user-event": "^12.8.3",
"history": "^5.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "6.0.0-beta.0",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
}
you have to export the component as default for instance
export default const Pizzas = () => <div>Pizzas...</div>;
to be able to import this way
const Pizzas = () => lazy(() => import('./Components/Pizzas'));

Element type is invalid when i wrap my app with <Provider>

I get an error when i try wrapping my <App> with <Provder>, here is the code
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import reducer from './store/reducer';
const store = createStore(reducer);
ReactDOM.render(<Provider store={store}><App /></Provider>, document.getElementById('root'));
registerServiceWorker();
Here is the error i get after i use <Provider>:
And here is my package.json :
{
"name": "react-complete-guide",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.7.0",
"react-dom": "^16.0.0",
"react-redux": "^6.0.0",
"react-scripts": "1.0.13",
"redux": "^4.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
In the end i realize this is probably related to a conflict of version in my package.json, but now matter how much i update each package i can't fix this, i also tried common fixes suggested in other threads with a similar problem but still no luck.
Thanks.
Update 01 :
App.js :
import React, { Component } from 'react';
import Counter from './containers/Counter/Counter';
import './App.css';
class App extends Component {
render() {
return (
<div className="App">
<Counter />
</div>
);
}
}
export default App;

react-bootstrap not working as expected

I am trying to use react-bootstrap to style a web page.
package.json
{
"name": "chrome-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-scripts": "1.0.16"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"react-bootstrap": "^0.31.5"
}
}
App.js
import React from 'react';
import { Button } from 'react-bootstrap'
function CheckState(props){
function handleClick(e){
console.log(props.state)
}
return(
<Button bsStyle="primary" onClick={handleClick}>Click for state</Button>
)
}
However this is what I'm seeing on the web page when I refresh:
It doesn't look like the styling is being added. What am I doing wrong?
Add import "bootstrap/dist/css/bootstrap.css"; in your index.js
In your react application, open index.js file and add import 'bootstrap/dist/css/bootstrap.css';

Reactstrap NavDropdown component doesn't open

I am still new to react and am trying to use react and reactstrap for an internal project at work. I have spent several hours trying to the get the NavDropdown component to work. I have tried porting the example code from https://reactstrap.github.io/components/dropdowns/ into my project to just test it out and built my own nav taking cues from this example https://codepen.io/eddywashere/pen/KgjQay?editors=0010
However, I cannot get the Dropdown menu to open.
When I inspect the element I can see the NavDropdown and its child elements in the inspector. When I click on the DropDown element I can see that its state.isOpen toggles to true. However- the dropdown menu doesn't actually show, it remains closed.
I have no console.log errors and am really mystified about what I am doing wrong. Would love to learn my mistake on this one so we can use the library.
Here is the header component I am trying to use the NavDropDown in:
import React from 'react';
import { Navbar, Nav, NavDropdown, DropdownToggle, DropdownMenu, DropdownItem} from 'reactstrap';
class Header extends React.Component {
constructor(props) {
super(props);
this.state = {
dropdown: false
};
this.dropdownToggle = this.dropdownToggle.bind(this);
}
dropdownToggle() {
this.setState({
dropdown: !this.state.dropdown
});
}
render() {
return (
<header>
<Navbar color="light">
<Nav navbar>
<NavDropdown isOpen={this.state.dropdown} toggle={this.dropdownToggle}>
<DropdownToggle color="primary" nav caret>
Dropdown
</DropdownToggle>
<DropdownMenu>
<DropdownItem>Header</DropdownItem>
<DropdownItem>Action</DropdownItem>
<DropdownItem>Another Action</DropdownItem>
<DropdownItem>Another Action</DropdownItem>
</DropdownMenu>
</NavDropdown>
</Nav>
</Navbar>
</header>
);
}
}
export default Header
Here is App.js file I import the header into:
import React from 'react';
import Header from './shared/Header';
class App extends React.Component {
render() {
return (
<div>
<Header/>
</div>
);
}
}
export default App;`
Here is my index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom'
import App from './comp/App';
import registerServiceWorker from './registerServiceWorker';
import 'bootstrap/dist/css/bootstrap.css';
import './Index.css';
ReactDOM.render(
<BrowserRouter><App /></BrowserRouter>,
document.getElementById('root')
);
registerServiceWorker();
I used create-react-app to start the project and here is my package.json
{
"name": "estimator",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^4.0.0-alpha.6",
"node-sass-chokidar": "0.0.3",
"prop-types": "^15.5.10",
"react": "^15.6.1",
"react-addons-css-transition-group": "^15.6.0",
"react-addons-transition-group": "^15.6.0",
"react-burger-menu": "^2.1.4",
"react-dom": "^15.6.1",
"react-icons": "^2.2.5",
"react-loading": "^0.1.4",
"react-modal": "^2.2.4",
"react-router-dom": "^4.1.2",
"react-scripts": "1.0.11",
"reactstrap": "^4.8.0",
"redux-thunk": "^2.2.0"
},
"scripts": {
"build-css": "node-sass-chokidar src/ -o src/",
"watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive",
"start-js": "react-scripts start",
"start": "npm-run-all -p watch-css start-js",
"build": "npm run build-css && react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"npm-run-all": "^4.0.2"
}
}
I encountered this when I moved from react-bootstrap (using bootstrap 3.3.7) to reactstrap.
Even though my package.json indicated "bootstrap": "^4.0.0-alpha.6" my configuration was still pulling 3.3.7.
I deleted my node_modules/bootstrap folder, did an npm install and it started working.
Maybe something to check?

Resources