Here is a basic react-redux app (sandbox):
import React from "react";
import ReactDOM from "react-dom";
import { createStore } from "redux";
import { useDispatch, Provider, useSelector, useStore } from "react-redux";
const App = () => {
const store = useStore(); // <- how it gets the store object of Provider ?
const state = useSelector(s => s);
return <div>{state}</div>;
};
ReactDOM.render(
<Provider store={createStore((state, action) => 5)}>
<App />
</Provider>,
document.getElementById("root")
);
Now my question is:
How hooks like useStore gets the store object we set in <Provider store={store}> ?
If it was dom, we could use this.closest('.provider').getAttribute('store') to get the store attribute of the provider element in parents. But how we can do it in react?
I'm asking it because i want to understand how react-redux works behind the scenes.
Thanks.