I want to get two values in single method of Parent Component. Pass the props value from Child to Parent Component. What is the appropriate solution?
- Form.js (Child Component)
// First method -> Here I get the value in suggestion which is then
// passed to Parent Component via props
onSuggestionSelected = (event, {suggestion}) => {
this.props.getWeather(suggestion)
}
// Second method -> Here is the value which I want to pass via
// props
onClick = (e) => {
e.preventDefault()
const value = e.target.value
this.props.getWeather(value)
}
// Autosuggest Input Component
// Here I get suggestion value
<Autosuggest
onSuggestionSelected={this.onSuggestionSelected}
/>
// Button Component
// Here I pass the input value to onClick method
<MDBBtn
type="submit"
value={inputProps.value}
onClick={e => this.onClick(e)}
>
Search Weather
</MDBBtn>
- App.js (Parent Component)
getWeather = async (suggestion, value) => {
// Here I get suggestion values
const city = suggestion.name;
const country = suggestion.country;
// Here I get undefined
console.log('VALUE', value)
}
So, as per code above, How to get both values from Child Component? Is it possible? Any suggestions or changes