easy-peasy icon indicating copy to clipboard operation
easy-peasy copied to clipboard

Allow lodash-style string notation to select state and actions

Open psnehanshu opened this issue 4 years ago • 0 comments

This PR aims to allow the use of lodash-style get path notation to access state and actions. e.g.

const store = createStore({
  user: {
    name: 'John',
   change: action((state, payload) => { state.name = payload; })
  }
});

Earlier

function App() {
  const name = useStoreState(state => state.user.name);
  const change = useStoreActions(state => state.user.change);
}

Now

function App() {
  const name = useStoreState('user.name');
  const change = useStoreActions('user.change');
}

This is meant for just convenience and nothing else.

psnehanshu avatar Aug 05 '21 21:08 psnehanshu