Accessing component state from the outside without breaking modularity

Viewed 34

Say I have a component like this

function SomeComponent(props) {
  const [x, setX] = useState([]);
  const [y, setY] = useState([]);

  return <></>
}

Is there a way to access x and y in a sibling component without breaking modularity? By "sibling" I mean a component that's not a child, parent, or grandparent etc.

In other words, I want to access x and y:

  • without creating a global state
  • without using context
  • without storing the state in another component, and passing in setX and setY as props
1 Answers
Related