HenrikJoreteg / redux-bundler

Compose a Redux store out of smaller bundles of functionality.
https://reduxbundler.com
583 stars 46 forks source link

Adapter for React useReducer hook #43

Open alexkrolick opened 5 years ago

alexkrolick commented 5 years ago

Seems like these abstractions would be portable onto https://reactjs.org/docs/hooks-reference.html#usereducer ... what do you think?

phoniks commented 5 years ago

I'm also interested in this topic. Would love to be able to use hooks + redux-bundler together. I swear earlier today I saw another post where someone proposed just such a solution.

phoniks commented 5 years ago

ahh... it was a different package, but I wonder if the solution could be adapted to this package as well.

https://github.com/HenrikJoreteg/redux-bundler-react/issues/3

alexkrolick commented 5 years ago

I'm sure Redux itself will support a subscribe or select hook at some point. I was more interested in removing the Redux dependency and actually using the built-in React reducer hook for the store (plus context and memoization).

HenrikJoreteg commented 5 years ago

I'm interested in exploring combining hooks and redux-bundler too. I primarily use preact these days or I probably would already done it.

What I would imagine is instead of:

export default connect('selectValue', ({value}) => (
  <div>{value}</div>
))

you could do something along these lines (haven't given it a ton of thought yet, though):

export default () => {
  const value = useSelector('selectValue')
  return <div>{value}</div>
}

The perk would be that you can name the variable whatever you want.

aulneau commented 5 years ago

I think think issue would probably be better for either the react- or preact- redux bundler packages, right? I wrote a useConnect hook when hooks were first announced that you can check out here -> https://github.com/HenrikJoreteg/redux-bundler-react/issues/3

I thought about doing useSelector and useAction, but I felt like it was somewhat redundant compared to:

const WalletPage = ({ ...rest }) => {
  const { signedIn, wallets, doSignIn } = useConnect(
    'selectSignedIn',
    'selectWallets',
    'doSignIn'
  );

  return <Box>...</Box>

};
abuinitski commented 5 years ago

So I first thought of adding this to redux-bundler-react, but it seems like it's either a full-rewrite, or dragging both legacy and current approach at the same time. Not cool for nice projects, so I have published a package for this – https://github.com/abuinitski/redux-bundler-hook