Live data from Hacker News

Show HN: Redux with a UseState Hook

hooked-on-redux.js.org

21–24 of 24 posts

Re: Show HN: Redux with a UseState Hook

#21
post #15

Earlier quoted context omitted.

Probably a fair point. I hadn't really taken typescript into account for the purposes of this library.

Since in TS you can guarantee the user has optional chaining, so it may not be that big a change // instead of useHookedOnState('app.components.counterValue', 0) // maybe useHookedOnState(state => state.app?.components?.counterValue, 0) edit: on second thought, you're probably using that string in the setter as well. dang.

Yup, that's the "magic" part.

Re: Show HN: Redux with a UseState Hook

#22

I said this in another comment, but similarly to this, check out Redux Toolkit ( https://redux-toolkit.js.org ), the `slices` feature changed my view on Redux entirely. Basically you can have a per-feature slice of functionality rather than having actions, reducers, and constants spread around your code. It's analogous to what hooks did, encapsulating similar functionality.

RTK is great! The only thing I wish was a bit different is the `createAsyncThunk` function. It feels dirty providing the action-type string manually, when for all the other actions, this is essentially invisible.

Re: Show HN: Redux with a UseState Hook

#23
post #22

I said this in another comment, but similarly to this, check out Redux Toolkit ( https://redux-toolkit.js.org ), the `slices` feature changed my view on Redux entirely. Basically you can have a per-feature slice of functionality rather than having actions, reducers, and constants spread around your code. It's analogous to what hooks did, encapsulating similar functionality.

RTK is great! The only thing I wish was a bit different is the `createAsyncThunk` function. It feels dirty providing the action-type string manually, when for all the other actions, this is essentially invisible.

The idea of having some kind of special syntax in `createSlice` to support declaring thunks has definitely been suggested, and there's other libraries out there that do similar things. But, anything we add to our API has to be supported indefinitely. Because of that, I wanted to release `createAsyncThunk` and `createEntityAdapter` as "standalone" utilities first and see how they actually get used by the community.

I'm definitely open to potentially integrating them together down the road, but I'd rather take it one step at a time and make sure that we're really solving the right problems the right way.

If you do have any further feedback on RTK, please feel free to file issues for discussion!

Re: Show HN: Redux with a UseState Hook

#24
post #11

Earlier quoted context omitted.

This is similar to how I've always implemented Redux before using some of my own utilities, but it's nice they have an "official" way to do it now. Does it work well with TypeScript?

Yep, RTK is specifically written in TypeScript, and I have a co-maintainer (Lenz Weber) who has done an amazing job working on the TS typedefs to make sure it works well. See the "Usage with TypeScript" docs page: https://redux-toolkit.js.org/usage/usage-with-typescript

That's great!
Post reply on HN