0
My problem is the following I am doing an IMC application, and I intend to change only the body of the screen when the result appears, without updating the page . my big problem is that I can’t use inputs made in a Component to change the state of the father which is where this weight the height and age.
Father
import React, { Component } from 'react';
import Inputs from '../../components/home/index.js'
import { Container, Title} from './styles';
export default class Home extends Component {
state = {
peso: 0,
altura: 0,
idade: 0,
}
handleWeight = (e) => {
this.setState({ peso: e.target.value })
console.log(this.state)
}
handleHeight = (e) => {
this.setState({ altura: e.target.value })
console.log(this.state)
}
handleAge = (e) => {
this.setState({ idade: e.target.value })
console.log(this.state)
}
submitResult=()=>{
}
render() {
return (
<Container>
<Title>Imc Sincero</Title>
<div>
<Inputs SetWeight={this.handleweight} Setheight={this.handleHeight} Setage={this.handleAge} />
</div>
</Container>
)
}
}
Son :
import React from 'react';
import { Input } from './styles';
export default function Inputs(SetWeight,Setheight,Setage) {
return (
<>
<Input>
<span>Peso(g):</span>
<input type="number" onChange={SetWeight}></input>
</Input>
<Input>
<span>Altura(m)</span>
<input type="number" onChange={Setheight}></input>
</Input>
<Input>
<span>Idade</span>
<input type="number" onChange={Setage}></input>
</Input>
</>
)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
Thanks so much to learning I still have many doubts vlw same. !
– LuciannoDev