Simple React form is not showing the default value (reactHooks) - reactjs

I'm following the official React docs to build a simple form which, however, doesn't work as intended.
const [value, setValue] = useState("banana")
...
<form onSubmit={handleSubmit}>
<label>
Pick your favorite flavor:
<select value={value} onChange={handleChange}>
<option value="grapefruit">Grapefruit</option>
<option value="lime">Lime</option>
<option value="coconut">Coconut</option>
<option value="mango">Mango</option>
</select>
</label>
<input type="submit" value="Submit" />
</form>
As far as I understood, it has to display "banana" as the initial value, whereas it shows "grapefruit". Why is it so?
Here's the link to the docs: https://reactjs.org/docs/forms.html
In the "Forms" section there's an example from where I took the code. It, however, uses class-based components while I use reactHooks. Might it be the problem?
Many thanks!

It shows the first option because value isn't an attribute of <select>. If you want to select one, you need to add a selected attribute to one of the options.
For example:
<label>
Pick your favorite flavor:
<select onChange={handleChange}>
<option value="grapefruit">Grapefruit</option>
<option value="lime">Lime</option>
<option selected={true} value="coconut">Coconut</option>
<option value="mango">Mango</option>
</select>
</label>
<input type="submit" value="Submit" />
This is generally written as
const options = ["grapefruit", "lime", "coconut", "mango"];
const selectedValue = "lime";
<label>
Pick your favorite flavor:
<select onChange={handleChange}>
{options.map(o => (<option value={o} selected={o == selectedValue}>{o}</option>)}
</select>
</label>
<input type="submit" value="Submit" />

It is because banana is not in options. If option's value is not present then it will by default pick the first one(Default behaviour). DEMO
import "./styles.css";
import { useState } from "react";
export default function App() {
const [value, setValue] = useState("mango");
const handleChange = (e) => {
setValue(() => {
return e.target.value;
});
};
return (
<div className="App">
<select value={value} onChange={handleChange}>
<option value="grapefruit">Grapefruit</option>
<option value="lime">Lime</option>
<option value="coconut">Coconut</option>
<option value="mango">Mango</option>
</select>
</div>
);
}

Related

How to store selected values in useState

I am a beginner at React JS. I would like to learn how to store selected values in useState.
The form containts four different drop downs and I want to store this selected values in useState so that at the end of the multi step form, user can go back to edit the fields before sub.
import React, {useState} from 'react';
import './paperdetails.css';
import IncDecCounter from './IncDecCounter'
import {
Text
} from '#chakra-ui/react';
const PaperDetails = () => {
const [selected, setSelected] = useState();
return (
<div className='paper-details'>
<div className='paper-details_display_flex'>
<div className='left'>
<div className='left-calc_wrapper'>
<div>
<label>Type of Paper</label>
<select>
<option value="essay">Paraphrasing</option>
<option value="Custom Writing">Custom Writing</option>
<option selected value="Dissertation">Dissertation</option>
<option value="Research Paper">Research Paper</option>
<option value="essay">Essay</option>
<option value="Term Paper">Term Paper</option>
<option selected value="Admission Essay">Admission Essay</option>
<option value="Coursework">Coursework</option>
<option value="Book Review">Book Review</option>
<option selected value="Paraphrasing">Essay</option>
<option value="Physics Paper">Physics Paper</option>
</select>
</div>
<div>
<label>Study Level</label>
<select>
<option value="school">Bachelor</option>
<option value="college">College</option>
<option selected value="Bachelor">School</option>
<option value="Masters">Masters</option>
</select>
</div>
</div>
<div className='left_middle'>
<div className='calc-control'>
<label>Number of Pages</label>
<IncDecCounter />
</div>
<div className="select-deadline">
<label>Deadline</label>
<select className='deadline' value={selected} onChange={e=>setSelected(e.target.value)}>
<option value="1 hour">1 hour</option>
<option value="3 hours">3 hours</option>
<option selected value="8 hours">8 hours</option>
<option value="12 hours">12 hours</option>
<option value="24 hours">24 hours</option>
<option value="48 hours">48 hours</option>
<option selected value="3 days">3 days</option>
<option value="5 days">5 days</option>
<option value="7 days">7 days</option>
<option selected value="14 days">14 days</option>
</select>
<span color={'#785aec'} fontSize={'14px'}
fontWeight={'bold'}> Will be ready in: {selected}
</span>
</div>
</div>
<section className="writing-instructions">
<div className="writing_instructions">
<div className="d-flex">
<label className='instructions'>
Writing instructions
<span className='text-orange'> *required</span>
</label>
<input className="input-file" id="my-file" type="file"
accept="application/pdf,application/msword,
application/vnd.openxmlformats-officedocument.wordprocessingml.document"/>
<label tabindex="0" for="my-file" className="input-file-trigger">
<span className='span--underlinel-blue'> Upload writing Instructions</span>
</label>
</div>
<div className='text-area'>
<textarea className='text-area_main'
placeholder='Type your instructions here. Please provide as many details as possible.'></textarea>
</div>
</div>
</section>
</div>
<div className='right'>
<div className='total-row'>
<div className='total-text'>
<h1 className='total-text_h1'>Total:</h1>
<span className='span_price'>$0.00</span>
</div>
</div>
</div>
</div>
</div>
)
}
export default PaperDetails;
How to store multiple values in state
to do this ,you will need to define state for all four select box like this
const [seleccedValue1,setSelectedValue1]=useState(null);
const [seleccedValue2,setSelectedValue2]=useState(null);
const [seleccedValue3,setSelectedValue3]=useState(null);
const [seleccedValue4,setSelectedValue4]=useState(null);
then you will need to handle on change event of each select box like this
<select onChange={(e)=>{setSelectedValue1(e.target.value)}}>
<option value="essay">Paraphrasing</option>
<option value="Custom Writing">Custom Writing</option>
<option selected value="Dissertation">Dissertation</option>
<option value="Research Paper">Research Paper</option>
<option value="essay">Essay</option>
<option value="Term Paper">Term Paper</option>
<option selected value="Admission Essay">Admission Essay</option>
<option value="Coursework">Coursework</option>
<option value="Book Review">Book Review</option>
<option selected value="Paraphrasing">Essay</option>
<option value="Physics Paper">Physics Paper</option>
</select>
you can do the same for other select boxes as well
Please checkout this question:
It was already answered here:
React JSX: selecting "selected" on selected <select> option
Here is how you store value of any input field in useState();
const [selected,setSelected] = useState({});
function handleChange(event){
setSelected({...selected,[event.targe.id]=event.target.value});
}
return(
<select
id={"id_0"}
value={selected["id_0"]}
onChange={(event)=>(handleChange(event))}>
......."your code continue here"
and here is how you handle multiple input fields.
<select id={'id_1'} value={selected['id_1']}
onChange={(event)=>(handleChange(event))}/>
<select id={'id_2'} value={selected['id_2']}
onChange={(event)=>(handleChange(event))}/>

set default value for select in react js

i am trying to set default value that is if this.state.items.gender is female in select option it must show female and if it is male the default value must me male
<select name="gender"
onChange={this.changeHandler}
defaultValue={this.state.items.gender} //onload this value must show in select input
required
style={styles.select}
>
<option style={styles.option} value="Male">
Male
</option>
<option style={styles.option} value="Female">
Female
</option>
</select>
default value is not working on simple html selection. You can do using the condition in the option in select like this.
<select
name="gender"
onChange={this.changeHandler}
//onload this value must show in select input
required
style={styles.select}
>
<option style={styles.option} value="Male" selected={this.state.items.gender === "Male"}>
Male
</option>
<option style={styles.option} value="Female" selected={this.state.items.gender === "Female"}>
Female
</option>
</select>;
This works perfectly fine to me.
import { useState } from 'react';
export default function App() {
const [gender, setGender] = useState('Female');
return (
<select
name="gender"
onChange={/* on change handler function */}
defaultValue={gender}
required
>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
);
}

Field Form doesn't update selected value in option

I've React Final Form in my project. I have a problem with updating the displayed option in select. The entire form works fine, but doesn't change the display value.
function App() {
const [selectValue, setSelectValue] = useState();
return (
<Form
onSubmit={onSubmit}
initialValues={{}}
render={({ handleSubmit, form, submitting, pristine, values }) => (
<form onSubmit={handleSubmit}>
<label>Dish type</label>
<Field
name="type"
component="select"
defaultValue={selectValue}
onChange={(e) => setSelectValue(e.target.value)}
required
>
<option value="" />
<option value="pizza">pizza</option>
<option value="soup">soup</option>
<option value="sandwich">sandwich</option>
</Field>
</div>
</form>
)}
/>
);
On live-server option does not change its value. Displayed value is the same as the first time I selected.
Try to use the regular html select.
<select value={selectValue}
onChange={(e) => setSelectValue(e.target.value)}
required
>
<option value="" />
<option value="pizza">pizza</option>
<option value="soup">soup</option>
<option value="sandwich">sandwich</option></select>

When I submit the form in childComponent my page is refreshing in ReactJS

I have a quiz application that you can choose amount of question,difficulty etc.After submitting you will directed to quiz screen.I have a parent component called App and child component called StartScreen. I want to change some states in child component and submit them.After summitting I will see the quiz testing screen.In parent component I have a state called start.When I change start from false to true I will see the quiz screen.My problem is that, when I change start to true in child component it refresh the page.So I cant see quiz screen
Parent component
import './App.css';
import React, { useState, useEffect } from 'react';
import QuestionGrid from './components/QuestionGrid';
import StartScreen from './components/StartScreen';
function App() {
const [error, setError] = useState(null);
const [isLoaded, setIsLoaded] = useState(false);
const [items, setItems] = useState([]);
const [amount, setAmount] = useState("10");
const [category, setCategory] = useState("23");
const [difficulty, setDifficulty] = useState('easy');
const [start, setStart] = useState(false);
useEffect(() => {
fetch(
`https://opentdb.com/api.php?amount=${amount}&category=${category}&difficulty=${difficulty}&type=multiple`
)
.then((res) => res.json())
.then(
(result) => {
setIsLoaded(true);
setItems(result.results);
},
(error) => {
setIsLoaded(true);
setError(error);
}
);
}, [amount,category,difficulty]);
console.log(error);
console.log(isLoaded);
return start === true ? (
<div className="App">
<QuestionGrid isLoaded={isLoaded} items={items} />
</div>
) : (
<div>
<StartScreen amount={(e)=>setAmount(e)} category={(e)=>setCategory(e)} difficulty={(e)=>setDifficulty(e)}/>
</div>
);
}
export default App;
This is my child component
import React, { useState, useEffect } from 'react';
export default function startScreen(props) {
return (
<section className="mt-3">
<header className="text-center">
<h2>Welcome to QUIZ</h2>
</header>
<div className="col-sm-6 m-auto">
<form action="">
<input
onChange={(e)=>(props.amount(e.target.value))}
placeholder="Select amount of questions"
type="number"
name="trivia_amount"
id="trivia_amount"
class="form-control"
min="1"
max="50"
></input>
<select
class="form-select form-select-md "
aria-label=".form-select-lg example"
onChange={(e)=>(props.category(e.target.value))}
>
<option selected>Select the category</option>
<option value="any">Any Category</option>
<option value="9">General Knowledge</option>
<option value="10">Entertainment: Books</option>
<option value="11">Entertainment: Film</option>
<option value="12">Entertainment: Music</option>
<option value="13">Entertainment: Musicals & Theatres</option>
<option value="14">Entertainment: Television</option>
<option value="15">Entertainment: Video Games</option>
<option value="16">Entertainment: Board Games</option>
<option value="17">Science & Nature</option>
<option value="18">Science: Computers</option>
<option value="19">Science: Mathematics</option>
<option value="20">Mythology</option>
<option value="21">Sports</option>
<option value="22">Geography</option>
<option value="23">History</option>
<option value="24">Politics</option>
<option value="25">Art</option>
<option value="26">Celebrities</option>
<option value="27">Animals</option>
<option value="28">Vehicles</option>
<option value="29">Entertainment: Comics</option>
<option value="30">Science: Gadgets</option>
<option value="31">Entertainment: Japanese Anime & Manga</option>
<option value="32">
Entertainment: Cartoon & Animations
</option>{' '}
</select>
<select
class="form-select form-select-md mb-5"
aria-label=".form-select-lg example"
onChange={(e)=>(props.difficulty(e.target.value))}
>
<option selected>Select the difficulty</option>
<option value="any">Any Difficulty</option>
<option value="easy">Easy</option>
<option value="medium">Medium</option>
<option value="hard">Hard</option>
</select>
<button type="submit" value="true" className="btn btn-danger col-sm-4 m-auto d-flex justify-content-center" onClick={(e)=>(alert(e.target.value))}>
Submit
</button>
</form>
</div>
</section>
);
}
You need to stop page from reloading by using preventDefault
import React, { useState, useEffect, useCallback } from 'react';
export default function startScreen(props) {
const handleSubmit = useCallback((event) => {
event.preventDefault()
alert(event.target.value)
}, [])
return (
<section className="mt-3">
<header className="text-center">
<h2>Welcome to QUIZ</h2>
</header>
<div className="col-sm-6 m-auto">
<form action="">
<input
onChange={(e) => (props.amount(e.target.value))}
placeholder="Select amount of questions"
type="number"
name="trivia_amount"
id="trivia_amount"
class="form-control"
min="1"
max="50"
></input>
<select
class="form-select form-select-md "
aria-label=".form-select-lg example"
onChange={(e) => (props.category(e.target.value))}
>
<option selected>Select the category</option>
<option value="any">Any Category</option>
<option value="9">General Knowledge</option>
<option value="10">Entertainment: Books</option>
<option value="11">Entertainment: Film</option>
<option value="12">Entertainment: Music</option>
<option value="13">Entertainment: Musicals & Theatres</option>
<option value="14">Entertainment: Television</option>
<option value="15">Entertainment: Video Games</option>
<option value="16">Entertainment: Board Games</option>
<option value="17">Science & Nature</option>
<option value="18">Science: Computers</option>
<option value="19">Science: Mathematics</option>
<option value="20">Mythology</option>
<option value="21">Sports</option>
<option value="22">Geography</option>
<option value="23">History</option>
<option value="24">Politics</option>
<option value="25">Art</option>
<option value="26">Celebrities</option>
<option value="27">Animals</option>
<option value="28">Vehicles</option>
<option value="29">Entertainment: Comics</option>
<option value="30">Science: Gadgets</option>
<option value="31">Entertainment: Japanese Anime & Manga</option>
<option value="32">
Entertainment: Cartoon & Animations
</option>{' '}
</select>
<select
class="form-select form-select-md mb-5"
aria-label=".form-select-lg example"
onChange={(e) => (props.difficulty(e.target.value))}
>
<option selected>Select the difficulty</option>
<option value="any">Any Difficulty</option>
<option value="easy">Easy</option>
<option value="medium">Medium</option>
<option value="hard">Hard</option>
</select>
<button type="submit" value="true" className="btn btn-danger col-sm-4 m-auto d-flex justify-content-center" onClick={handleSubmit}>
Submit
</button>
</form>
</div>
</section>
);
}

"Cannot read property 'value' of undefined" error while submitting form data to my API in Reactjs

I'm using a Multi-step form to post the form data to my API. But I'm facing an issue while submitting the data. I do not understand how to use props to send the child component data to my parent component.
This is my parent component:
import React, { Component } from "react";
import StepOne from "views/StepOne";
import StepTwo from "views/StepTwo";
import StepThree from "views/StepThree";
import axios from "axios";
import "views/Typography.css";
class Help extends Component {
constructor(props) {
super(props)
this._next = this._next.bind(this)
this._prev = this._prev.bind(this)
// Set the initial input values
this.state = {
currentStep: 1, // Default is Step 1
productName: "",
productPrice: "",
productCategory: "",
productBrand: "",
countryOfOrigin: "",
riskType: "",
alertSubmittedBy: "",
yourCity: "",
yourAddress: "",
productImage: undefined,
description: "",
showMessage: false,
pname: "",
price: 0,
pCategory: "",
pBrand: "",
pCountryOfOrigin: "",
}
// Bind the submission to handleChange()
this.handleChange = this.handleChange.bind(this);
this.handleChange1 = this.handleChange1.bind(this);
this.handleChange2 = this.handleChange2.bind(this);
this.handleChange3 = this.handleChange3.bind(this);
this.onChangeHandlerPost = this.onChangeHandlerPost.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
//---------------------on change of file-------------------
handleChange(event) {
this.setState({ countryOfOrigin: event.target.value });
console.log(this.state.countryOfOrigin);
}
handleChange1(event) {
this.setState({ riskType: event.target.value });
console.log(this.state.riskType);
}
handleChange2(event) {
this.setState({ alertSubmittedBy: event.target.value });
console.log(this.state.alertSubmittedBy);
}
handleChange3(event) {
this.setState({ productCategory: event.target.value });
console.log(this.state.productCategory);
}
//-------------------------------------------------------
onChangeHandlerPost = (event) => {
this.setState({
productImage: event.target.files[0],
});
console.log(event.target.files[0]);
};
onClickHandler = (event) => {
console.log("Clicked");
this.setState({
showMessage: true,
});
};
//----------------------------handle Submit----------------
handleSubmit = (event) => {
event.preventDefault();
const form = new FormData();
form.append("productName", this.productName.value);
form.append("productPrice", this.productPrice.value);
form.append("productCategory", this.productCategory.value);
form.append("productBrand", this.productBrand.value);
form.append("countryOfOrigin", this.state.countryOfOrigin);
form.append("riskType", this.state.riskType);
form.append("alertSubmittedBy", this.state.alertSubmittedBy);
form.append("yourCity", this.yourCity.value);
form.append("yourAddress", this.yourAddress.value);
form.append("productImage", this.state.productImage);
form.append("description", this.textArea.value);
axios.post("https://alert-amigo-api.herokuapp.com/products", form, {
headers: { "Content-Type": "multipart/form-data" },
});
this.setState({ showMessage: true });
console.log("Clicked");
//---------------------------------------------------
/* const pname = this.productName.value;
const price = this.productPrice.value;
const pCategory = this.productCategory.value;
const pBrand = this.productBrand.value;
const pCountryOfOrigin = this.state.countryOfOrigin;
this.props.createProduct(pname, price, pCategory, pBrand, pCountryOfOrigin); */
};
_next() {
let currentStep = this.state.currentStep
// If the current step is 1 or 2, then add one on "next" button click
currentStep = currentStep >= 2? 3: currentStep + 1
this.setState({
currentStep: currentStep
})
}
_prev() {
let currentStep = this.state.currentStep
// If the current step is 2 or 3, then subtract one on "previous" button click
currentStep = currentStep <= 1? 1: currentStep - 1
this.setState({
currentStep: currentStep
})
}
// Use the submitted data to set the state
// handleChange(event) {
// const {name, value} = event.target
// this.setState({
// [name]: value
// })
// }
get previousButton(){
let currentStep = this.state.currentStep;
// If the current step is not 1, then render the "previous" button
if(currentStep !==1){
return (
<button
className="btn btn-secondary"
type="button" onClick={this._prev}>
Previous
</button>
)
}
// ...else return nothing
return null;
}
get nextButton(){
let currentStep = this.state.currentStep;
// If the current step is not 3, then render the "next" button
if(currentStep <3){
return (
<button
className="btn btn-primary float-right"
type="button" onClick={this._next}>
Next
</button>
)
}
// ...else render nothing
return null;
}
// Render UI will go here...
render() {
return (
<React.Fragment>
<div>
<div className="alert-1">
<h3 className="a">
Report a Product <i className="pe-7s-news-paper"></i>
</h3>
<hr className="new1"></hr>
<p className="k">
Please check if the product you want to report has already been
reported earlier using the <b>"Search"</b> option.
</p>
<p className="k">
{" "}
If you couldn't find the product there, then you can <b>
"Report"
</b>{" "}
the product here.
</p>
<p className="k">
{" "}
Please ensure to fill in all the required details and ensure that
the details entered by you are correct.
</p>
</div>
<br />
<br />
<div className="container1">
<p>Step {this.state.currentStep} </p>
<form onSubmit={this.handleSubmit}
id="myForm"
method="POST"
encType="multipart/form-data">
<StepOne
currentStep={this.state.currentStep}
onChange={this.handleChangePost}
onChange={this.handleChange3}
productName={this.state.productName}
productPrice={this.state.productPrice}
productCategory={this.state.productCategory}
productBrand={this.state.productBrand}
handleChange={this.handleChange}
/>
<StepTwo
currentStep={this.state.currentStep}
handleChange={this.handleChange}
onChange={this.handleChange1}
onChange={this.handleChange2}
/>
<StepThree
currentStep={this.state.currentStep}
handleChange={this.handleChange}
onChange={this.handleChangePost}
onChange={this.onChangeHandlerPost}
/>
{this.previousButton}
{this.nextButton}
</form>
<br />
<div>
{this.state.showMessage && (
<div className="alert alert-success">
<strong>Success!</strong> successful submitted a report
</div>
)}
</div>
</div>
</div>
</React.Fragment>
)
}
}
export default Help
These are my child components:
I want to know how to use props to send the field data to the parent component
import React, { Component } from "react";
class StepOne extends React.Component {
render() {
if (this.props.currentStep !== 1) { // Prop: The current step
return null
}
// The markup for the Step 1 UI
return(
<div className="form-group">
<label> Product Name: </label>
<input
className="form-control"
id="productName"
type="text"
ref={(input) => {
this.productName = input;
}}
placeholder="Product Name"
required
// Prop: The email input data
onChange={this.props.handleChangePost} // Prop: Puts data into state
/>
<label> Product Price: </label>
<input
id="productPrice"
type="text"
ref={(input) => {
this.productPrice = input;
}}
onChange={this.props.handleChangePost}
className="form-control"
placeholder="Product Price in Euros (€)"
required
/>
<label>
Product Category:
<select
id="productCategory"
value={this.productCategory}
onChange={this.handleChange3}
required
>
<option value="Toys">Toys</option>
<option value="Motor vehicles">Motor vehicles</option>
<option value="Clothing, textiles and fashion items">Clothing, textiles and fashion items</option>
<option value="Electrical appliances and equipment">Electrical appliances and equipment</option>
<option value="Childcare articles and children's equipment">Childcare articles and children equipment</option>
<option value="Cosmetics">Cosmetics</option>
<option value="Jewellery">Jewellery</option>
<option value="Other">Other</option>
</select>
</label>
<br/>
<label> Brand Name: </label>
<input
id="productBrand"
type="text"
onChange={this.handleChangePost}
ref={(input) => {
this.productBrand = input;
}}
className="form-control"
placeholder="Product Brand"
required
/>
</div>
)
}
}
export default StepOne
import React, { Component } from "react";
class StepTwo extends React.Component {
render() {
if (this.props.currentStep !== 2) {
return null
}
return(
<div className="form-group">
<label>
Country of origin:
<select
id="countryoforigin"
value={this.countryoforigin}
onChange={this.handleChange}
required
>
<option>--select--</option>
<option value="albania">Albania</option>
<option value="algeria">Algeria</option>
<option value="argentina">Argentina</option>
<option value="austria">Austria</option>
<option value="bangladesh">Bangladesh</option>
<option value="barbados">Barbados</option>
<option value="belarus">Belarus</option>
<option value="belgium">Belgium</option>
<option value="bosnia and Herzegovina">
Bosnia and Herzegovina
</option>
<option value="Brazil">Brazil</option>
<option value="Bulgaria">Bulgaria</option>
<option value="Combodia">Combodia</option>
<option value="Cameroon">Cameroon</option>
<option value="Canada">Canada</option>
<option value="Chile">Chile</option>
<option value="china">China</option>
<option value="Cocos (Keeling) Islands">
Cocos (Keeling) Islands
</option>
<option value=" Colombia"> Colombia</option>
<option value="Congo">Congo</option>
<option value=" Croatia"> Croatia</option>
<option value="Cyprus">Cyprus</option>
<option value=" Czech Republic"> Czech Republic</option>
<option value=" Democratic People's Republic of Korea">
{" "}
Democratic People's Republic of Korea
</option>
<option value="Democratic Republic Of Congo">
Democratic Republic Of Congo
</option>
<option value=" Denmark"> Denmark</option>
<option value="Dominican Republic">Dominican Republic</option>
<option value=" Ecuador"> Ecuador</option>
<option value="Egypt">Egypt</option>
<option value="Estonia">Estonia</option>
<option value="Finland">Finland</option>
<option value="Former Yugoslav Republic of Macedonia">
Former Yugoslav Republic of Macedonia
</option>
<option value="France">France</option>
<option value="Germany">Germany</option>
<option value="Greece">Greece</option>
<option value="Guatemala">Guatemala</option>
<option value=" Guinea-Bissau"> Guinea-Bissau</option>
<option value="Hong Kong">Hong Kong</option>
<option value="Hungary">Hungary</option>
<option value="Iceland">Iceland</option>
<option value="India">India</option>
<option value="Indonesia">Indonesia</option>
<option value=" Iran"> Iran</option>
<option value=" Ireland"> Ireland</option>
<option value="Israel">Israel</option>
<option value="Italy">Italy</option>
<option value="Ivory Coast">Ivory Coast</option>
<option value="Jamaica">Jamaica</option>
<option value="Japan">Japan</option>
<option value="Jordan">Jordan</option>
<option value=" Lao People's Democratic Republic">
{" "}
Lao People's Democratic Republic
</option>
<option value=" Latvia"> Latvia</option>
<option value="Lebanon">Lebanon</option>
<option value="Lithuania">Lithuania</option>
<option value="Luxembourg">Luxembourg</option>
<option value="Madagascar">Madagascar</option>
<option value="Malaysia">Malaysia</option>
<option value=" Mali"> Mali</option>
<option value="Malta">Malta</option>
<option value="Mexico">Mexico</option>
<option value="Monaco">Monaco</option>
<option value="Morocco">Morocco</option>
<option value=" Mozambique"> Mozambique</option>
<option value=" Namibia"> Namibia</option>
<option value="Nepal">Nepal</option>
<option value="New Zealand">New Zealand</option>
<option value=" Nicaragua"> Nicaragua</option>
<option value="Nigeria">Nigeria</option>
<option value="Norway">Norway</option>
<option value="Pakistan">Pakistan</option>
<option value="Paraguay">Paraguay</option>
<option value="People's Republic of China">
People's Republic of China
</option>
<option value="Peru">Peru</option>
<option value="Philippines">Philippines</option>
<option value="Poland">Poland</option>
<option value="Portugal">Portugal</option>
<option value="Republic of Korea">Republic of Korea</option>
<option value="Republic of Moldova">
Republic of Moldova
</option>
<option value="Romania">Romania</option>
<option value="Russia">Russia</option>
<option value="Russian Federation">Russian Federation</option>
<option value="Saudi Arabia">Saudi Arabia</option>
<option value="Senegal">Senegal</option>
<option value="Serbia">Serbia</option>
<option value="Singapore">Singapore</option>
<option value="Slovakia">Slovakia</option>
<option value="Slovenia">Slovenia</option>
<option value="South Africa">South Africa</option>
<option value="South Korea">South Korea</option>
<option value="Spain">Spain</option>
<option value="Sri Lanka">Sri Lanka</option>
<option value="Sweden">Sweden</option>
<option value="Switzerland">Switzerland</option>
<option value="Syria">Syria</option>
<option value="Taiwan">Taiwan</option>
<option value="Thailand">Thailand</option>
<option value="The Bahamas">The Bahamas</option>
<option value="The Netherlands">The Netherlands</option>
<option value="Togo">Togo</option>
<option value="Tunisia">Tunisia</option>
<option value="Turkey">Turkey</option>
<option value="Ukraine">Ukraine</option>
<option value="United Arab Emirates">
United Arab Emirates
</option>
<option value="United Kingdom">United Kingdom</option>
<option value="United States">United States</option>
<option value="Uruguay">Uruguay</option>
<option value="Vietnam">Vietnam</option>
</select>
</label>
<label>
Risk Type or Level:
<select
id="risktype"
value={this.risktype}
onChange={this.handleChange1}
required
>
<option>--select--</option>
<option value="very low">very low</option>
<option value="low">low</option>
<option value="medium">medium</option>
<option value="High">High</option>
</select>
</label>
<label>
Alert Submitted by:
<select
id="alertsubmittedby"
value={this.alertsubmittedby}
onChange={this.handleChange2}
required
>
<option>--select--</option>
<option value="consumer">Consumer</option>
<option value="producer">Producer</option>
<option value="supplier">Supplier</option>
<option value="eu Authorities">Eu Authorities</option>
</select>
</label>
</div>
);
}
}
export default StepTwo
import React, { Component } from "react";
class StepThree extends React.Component {
render() {
if (this.props.currentStep !== 3) {
return null
}
return(
<React.Fragment>
<div className="form-group">
<label>Notifiers data</label>
<input
id="yourCity"
type="text"
onChange={this.handleChangePost}
ref={(input) => {
this.yourCity = input;
}}
className="form-control"
placeholder="Your city"
required
/>
<label>Address</label>
<input
id="yourAddress"
type="text"
onChange={this.handleChangePost}
ref={(input) => {
this.yourAddress = input;
}}
className="form-control"
placeholder="Your Address"
required
/>
<label> Upload Images: </label>
<input
name="uploadFile"
type="file"
onChange={this.onChangeHandlerPost}
ref={(input) => {
this.uploadFile = input;
}}
className="form-control"
placeholder="upload Images"
required
/>
<label> Description </label>
<textarea
name="textArea"
onChange={this.handleChangePost}
ref={(input) => {
this.textArea = input;
}}
className="form-control"
placeholder="Write here.."
required
col="5"
row="15"
/>
</div>
<br />
<button type="submit" className="mt-auto btn btn-primary" id="new2">Submit</button>
</React.Fragment>
);
}
}
export default StepThree
React architecture based on unidirectional data flow. Which means the
data flows only from parent to child. You can use third party
libraries such as Redux or can also use newest feature of React which
is ContextAPI.

Resources