I'm not sure why (I'm new to React) but I'm getting a simple error when trying to render a simple component 'Intros.js'. Here is the component:
Intros.js:
import React from 'react';
import PropTypes from 'prop-types';
const Intros = (summary) => {
return (
<div className='intros'>
ERROR HERE: {summary} variable can't be wrapped in curly braces; reason
unknown
</div>
);
};
Intros.propTypes = {
summary: PropTypes.string.isRequired,
};
Intros.defaultProps = {
summary: 'Summary...',
};
export default Intros;
If I change {summary} to summary then the error does not occur, but then I'd not be able to pass props down in App.js. Below is the App.js file:
App.js:
import React, { Fragment } from 'react';
import './App.css';
import Navbar from './components/layout/Navbar';
import Intros from './components/layout/Intros';
import {
BrowserRouter as Router,
Route,
Switch,
NavLink,
} from 'react-router-dom';
const App = () => {
return (
<Router>
<Fragment>
<Navbar />
<Intros />
</Fragment>
</Router>
);
};
export default App;
Note that the above passes down no prop but should have a default prop anyway. Below is also the error when {summary} is used in the component:
Error occurred:
Objects are not valid as a React child (found: object with keys {summary}). If you meant to render a collection of children, use an array instead.
in div (created by Intros)
in Intros (created by App)
in Router (created by BrowserRouter)
in BrowserRouter (created by App)
in App
in StrictMode
Why does this error occur, and how can I change Intros.js to use the summary variable as a prop? Using this.props.summary also fails.
Thanks for any help. Here is a Stackblitz demo