I have a component which contains an <input type="range"></input> element. In that component I have a function that changes the state when that slider is moved.
I would like to not only be able to use that state to change the span tag inside the Slider component but also 2 other sibling components which will be rendering that same value.
So as I move that slider I want to see the value change on multiple places on the screen.
Slider.jsx
function Slider() {
const [value, setValue] = useState(0.50)
const handleChange = (event) => {
setValue(event.target.value);
}
return (
<div className='slider'>
<div className="label">
<label htmlFor="value">Value</label>
<span>{value}</span>
</div>
<input onChange={handleChange} type="range" id="value" name="value" min="0.00" max="100.00" step='0.01'></input>
</div>
)
}
Component1.jsx
function Component1() {
return (
<div>
<p>{value}</p>
</div>
)
}
Component2.jsx
function Component2() {
return (
<div>
<p>{value}</p>
</div>
)
}
Here's the structure of my app, as you can see Component1 and Component2 are siblings of Slider.
├── App.js
├── components
│ ├── Slider.jsx
│ ├── Component1.jsx
│ └── Component2.jsx