I have a button and I need for the button to change a parent state value on click.
I know there are tons of questions like this but I swear I just can't understand it.
I have tried lifting the state up but I just can't get it right
home page button http://prntscr.com/n8jnlh
import React, { Component,Fragment } from 'react'
import App from '../App.css'
import productPage from '../ProductPage'
class NinjaH2R extends Component {
render () {
return (
<Fragment>
<table> {/*lista de produtos */}
<td className="drop">
<div className="dropdown">
<button className="dropbtn">Motos ˅</button>
<div className="dropdown-content">
<div>
<button /*onClick={this.handleClick.bind(this)}*/ >Ninja
400</button>
</div>
</td>
</table>
</Fragment>
)
}
}
export default NinjaH2R
parent state I want to change http://prntscr.com/n8jo07
import React, { Component,Fragment } from 'react'
import Ninja400 from './components/Ninja400'
import product from './productJSON';
import App from './App.css'
import NinjaZX6R from './components/NinjaZX6R';
import Z900 from './components/Z900';
import NinjaH2R from './components/NinjaH2R';
import Toggle from './components/Toggle'
class ProductPage extends Component {
constructor(props){
super(props)
this.state = {
toggle400: false,
toggleZX6R: false,
toggleZ900: false,
toggleH2R: true,
}
let modelo
}
render () {
let modelo=null
if(this.state.toggle400===true){
modelo=<Ninja400 product={product}/>
this.state.toggleZX6R = false
this.state.toggleZ900 = false
this.state.toggleH2R = false
}
if(this.state.toggleZX6R===true){
modelo=<NinjaZX6R product={product}/>
this.state.toggle400 = false
this.state.toggleZ900 = false
this.state.toggleH2R = false
}
if(this.state.toggleZ900===true){
modelo=<Z900 product={product}/>
this.state.toggleZX6R = false
this.state.toggle400 = false
this.state.toggleH2R = false
}
if(this.state.toggleH2R===true){
modelo=<NinjaH2R product={product}/>
this.state.toggleZX6R = false
this.state.toggleZ900 = false
this.state.toggle400 = false
}
console.log(this)
return (
<Fragment >
<div className="ProductPage">
{modelo}
</div>
</Fragment>
)
}
}
export default ProductPage
When I click on the button located at the NinjaH2R component, I need it to change the state of the prop "toggle400" to true, located at the ProductPage component