0

I'm new to react and i wanted to get range value from child component(salary.js) to parent component(App.js). i couldn't able to find out how to pass the props to App component. My objective is get the range value which is stored in salary.js to App.js in price in order to post the value.

Can anyone please help me in this? Thanks in advance

1

2 Answers 2

1

U can use callback function.

PaterentComponent  {

  const myCallbackFunction = (value) => {
  console.log(value);
  }

  return (
    <ChildComponent callback={myCallbackFunction}> </ ChildComponent>
  )
}

ChildComponent {

/// dothmth

   return <button  onClick{props.myCallbackFuntion("I'mcallback")}>CallbackFunciton</button>

}
Sign up to request clarification or add additional context in comments.

Comments

0

You cannot pass props from a component to its parent. You need to store the rangeValue inside your App component. It's called "lifting state up". Your App component should pass the rangeValue and a callback to modify it to Salary. Salary will then display the value it received from props and call the callback whenever the value needs to be updated

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.