I am new to ReactJS and web dev in general.
I am creating a web app in which I input a string (a mathematical expression) from the user. After pressing the submit button I want to process this string in a python script and return the desired output in the Output TextBox. How can I make this python script a permanent part of my web-app.
The input textbox and submit button are part of the Submit component in a file "Submit.js". The output textbox is the part of the Solution component in a file "Solution.js".
Both of these components are children to the LeftWindowComponent. I am storing values of both the textboxes in the state of the parent component i.e the LeftWindowComponent. The state "fx" defines the text in Input textbox. The state "fprimex" defines the text in Solution (Output) textbox.
Code for Submit component -->
class Submit extends Component{
constructor(props){
super(props);
}
render(){
return(
<div className="center">
<div>
<Form onSubmit={this.handleSubmit}>
<Col md={{ size: 6, offset: 3 }} >
<FormGroup row>
<Input type="text" id="fx" name="fx" placeholder="Type Here" value = {this.props.fx} onChange={this.props.handleInputChangeFromKeyboard} />
</FormGroup>
</Col>
</Form>
<Button type="submit" color="primary">Differentiate</Button>
</div></div>
)
}
}
Code for Solution component -->
class Solution extends Component{
constructor(props){
super(props);
}
render(){
return(
<div class = "center">
<Form>
<FormGroup>
<Col md={{size:8,offset:2}}>
<Input type="textarea" id="fprimex" name="fprimex" placeholder="Solution" value = {this.props.fprimex} />
</Col>
</FormGroup>
</Form>
</div>
)
Code for LeftWindow Component -->
class LeftWindow extends Component{
constructor(props){
super(props);
this.state = {
fx: "",
fprimex: "",
};
}
handleInputChange = (newInput) => {
this.setState({
fx: this.state.fx.concat(newInput),
});
} ;
handleInputChangeFromKeyboard = (event) => {
const target = event.target;
const value = target.value;
const name = target.name;
this.setState({
[name]: value
});
} ;
render(){
return(
<div className="col-12 bg-dark fullheight">
<h3 className="center">Enter the function to be differentiated</h3>
<Buttons handleInputChange={this.handleInputChange} />
<Submit fx = {this.state.fx} handleInputChange={this.handleInputChange} handleInputChangeFromKeyboard = {this.handleInputChangeFromKeyboard}/>
<Solution fprimex = {this.state.fprimex}/>
</div>
);
}
}
Thanks in advance!