How do i append an external reactjs component onClick using hooks

338 Views Asked by At

i'm completely new to reactjs. How do i append an external jsx with an onClick function(Just once) using react hooks?

1

There are 1 best solutions below

0
On

You can use an array variable in your main jsx(App.js) state like shown below

    state = {
        externaljsx: []
    }

For button onClick event call function addExternal to add external JSX

    addExternal = () => {
        this.setState({
             externaljsx: [this.state.externaljsx, <NameofyourJSX />]
        })
    }

Please note should be your JSX component name.