I think there will be two methods to do this.
- Be a child of the same parent and share props.
import {useState} from "React"
const TestOneComponent = ({value}) => (
<span>{value.toString()}<span>
)
const TestTwoComponent = ({value, onClick}) => (
<span>{value.toString()}</span>
<button onClick={onClick}>Increase Value</button>
)
const ParentComponent = () => {
const [value, setValue] = useState(0)
const onClick = () => {
setValue(value + 1)
}
return (
<>
<TestOneComponent value={value}>
<TestTwoComponent value={value} onClick={onClick}>
</>
)
}
- Manage store and pass props to those two components.