All that means is the selector is a function that only consumes a state
object and thus has no external dependencies.
Could someone provide some examples of when the state depends on the
scope so that the selector should not be used?
Scope wouldn't affect when or where a selector function could be used, but rather where it can be declared. Selector functions without dependencies other than state
can be declared external to any component using them.
You could write a selector function that also references a value defined in the component, so the value would be an external dependency.
const MyComponent = () => {
const value = ......;
const selector = state = {
// use enclosed value to compute returned value from state
... do something with value
};
const valueFromState = useStore(selector);
...