I have a simple page developed using React, the page has a Menu component which has a callback as props (targetPage), when the callback starts, a component is received and then it will be to insert into the page.
But this procedure fails, giving this error,
class constructors must be invoked with 'new'
basicStateReducer@http://localhost:3000/static/js/bundle.js:22501:45
updateReducer@http://localhost:3000/static/js/bundle.js:22610:26
...
this is source code
main app
import React, {useState} from 'react';
function App() {
const [currentPage, setCurrentPage] = useState<any>();
return (
<div className="App">
<Menu
targetPage={ (page: any) => {
setCurrentPage( page );
}}
/>
<div id={'target-page'}>
{ !!currentPage ? currentPage : (<img src={'https://localhost/logo'} /) }
</div>
</div>
);
}
export default App;
menu component
import pageComponent from '.';
export const Menu = (props:{targetPage:any}) => (
<div
onClick={ clickEvent => {
props.targetPage( pageComponent );
}}
>
click
</div>
)
component
import React from 'react';
export default class pageComponent extends React.Component<any, any> {
state = {}
constructor(props: any) {
super( props );
}
render() {
let content = (
<div>Page</div>
);
return content;
}
}
how can I does it get a component from a callback passed as porps?