Live data from Hacker News

A SoundCloud client in React and Redux

robinwieruch.de

31–40 of 74 posts

Re: A SoundCloud client in React and Redux

#31
post #25

There seems to be a big blind spot in these Real World React+Redux tutorials when it comes to forms. For example, say I have a page with reviews on it. So there's a Component that handles editing a review. Where does the state for all the form inputs go? Does it go in the Redux store? If it does, then every time the user types a letter you get an event, which goes walking backward through the component tree until it…

I agree with your point and disagree with redux-form being a valid solution. redux-form creates a very restricted and crippled API for getting form data into a redux state object and does so at the expense of the spirit of React's componentized model. Any redux-form state needs to be isolated under a special root object specifically for forms. You can't just mount some existing part of your state object into a form b…

Also tried redux form and while the creator is very talented it was just more trouble than it was worth for our team. There's a real opportunity to create a sound abstraction to forms with react and redux right now. I've investigated this heavily and no existing approach works how I'd like.

What I want is a higher order component for a given form parent specified by a string, with higher order components for all common html5 form types which are stored in a state tree child node based on a string for the form parent and each component which encapsulates form elements, and rolls up small change events to avoid event log spam.

I originally thought a json or other dsl solution would be ideal, but that ends up being an integration and interoperability headache. Jsx as a dsl works better than json as a dsl for ui in my experience. The big question is where to store the "batched" changes before being rolled up.

I think rather than component setstate, perhaps a sub tree in the redux store with its own subtrees could exist with a specific prefix that could be hidden in the redux devtools chrome extension to avoid the spam problem. I rather like this solution, as it would make react and redux forms beat the simplicity of angular 1 forms with all the benefits react and redux bring. Would other people use it? Anything like it exist already? Maybe I'll create this...

Re: A SoundCloud client in React and Redux

#32

The past few days I have really been getting into the 3REE stack: React, Redux and RethinkDB and have been learning so much. Here's a blog[1] outlining it and a github example of it [2]. It has been great so far, what are some UI libraries that I should take a look at, so far this looks like the best option[3] [1] http://blog.workshape.io/the-3ree-stack-react-redux-rethinkd... [2] https://github.com/GordyD/3ree [3] h…

In my own app, I'm using Semantic-UI as the styling baseline, especially for inputs. There's a number of React wrappers around Semantic-UI, such as https://github.com/hallister/semantic-react and https://github.com/TechnologyAdvice/stardust, but most of them create React wrappers around Semantic's jQuery-based widgets. I'm trying to avoid use of jQuery entirely, so I opted for https://github.com/shinzui/react-semantic-ui-kit instead. Not as complete as the other libs, but a great focus on just wrapping the CSS/className aspects of Semantic-UI.

Beyond that, https://github.com/jquense/react-widgets is a great set of more specialized input widgets (dropdowns, datetime picker, numeric spinner, etc), and https://github.com/rofrischmann/react-layout-components is a good React wrapper around Flexbox usage.

Re: A SoundCloud client in React and Redux

#33
post #19

There seems to be a big blind spot in these Real World React+Redux tutorials when it comes to forms. For example, say I have a page with reviews on it. So there's a Component that handles editing a review. Where does the state for all the form inputs go? Does it go in the Redux store? If it does, then every time the user types a letter you get an event, which goes walking backward through the component tree until it…

Everyone basically just uses Redux Form ( http://redux-form.com/5.2.5/ ) as near as I can tell; it really works well. It basically works as per your first guess: Everything goes in the store. And no, it doesn't really have any performance or efficiency issues. Try it out and see. :)

The overhead for a simple textarea seems significant. On Firefox there are stalls (up to 500 ms) if I type "fast". I've tested the form on http://redux-form.com/5.2.5/#/examples/simple?_k=8ukhm8 (specifically the textarea).

Here is the CPU time graph during my tests: http://imgur.com/we9uGQ7

EDIT: OK apparently it's not accurate, see comment below.

Re: A SoundCloud client in React and Redux

#34

There seems to be a big blind spot in these Real World React+Redux tutorials when it comes to forms. For example, say I have a page with reviews on it. So there's a Component that handles editing a review. Where does the state for all the form inputs go? Does it go in the Redux store? If it does, then every time the user types a letter you get an event, which goes walking backward through the component tree until it…

Your concerns about input events moving up and down the component tree seem misplaced. It’s what happens when you use React anyway (unless you’re only using local component state); putting these input values in the Redux store only makes things simpler.

As for the fact that it changes the state and adds noise to the log… these seem like aesthetic judgments on your part. Why is changing an input “noise”? It’s an important part of the data on the page.

Re: A SoundCloud client in React and Redux

#35
post #30

Earlier quoted context omitted.

I'd be interested in seeing what you put together. Is that available somewhere?

Not yet, but it will be! https://github.com/studionone/ is where it will live, plan is to release it this week, all things going well.

Cool. I'll keep an eye out for it!

Re: A SoundCloud client in React and Redux

#36
post #27
post #25

Earlier quoted context omitted.

I agree with your point and disagree with redux-form being a valid solution. redux-form creates a very restricted and crippled API for getting form data into a redux state object and does so at the expense of the spirit of React's componentized model. Any redux-form state needs to be isolated under a special root object specifically for forms. You can't just mount some existing part of your state object into a form b…

> I question whether people use it in large scale production. We tried to, and removed it within 4 weeks of development with it, for all of the reasons you mentioned. It conceptually doesn't map to our Redux model, and new developers struggled with it because of that. I ended up writing my own "wrapper" to do something similar, but to be honest for most of our form state it is handled within the components themselves…

What are the pros/cons of setstate vs a batched state subtree for each component and an aggregate state subtree for each component that matched each form parent, specified by a string to a higher order component for the parent form and a string for each component used to model html5 form inputs?

Re: A SoundCloud client in React and Redux

#37
post #34

There seems to be a big blind spot in these Real World React+Redux tutorials when it comes to forms. For example, say I have a page with reviews on it. So there's a Component that handles editing a review. Where does the state for all the form inputs go? Does it go in the Redux store? If it does, then every time the user types a letter you get an event, which goes walking backward through the component tree until it…

Your concerns about input events moving up and down the component tree seem misplaced. It’s what happens when you use React anyway (unless you’re only using local component state); putting these input values in the Redux store only makes things simpler. As for the fact that it changes the state and adds noise to the log… these seem like aesthetic judgments on your part. Why is changing an input “noise”? It’s an impor…

For me the batched changes are useful, but single character changes can make the event log overly verbose.

Re: A SoundCloud client in React and Redux

#38

There seems to be a big blind spot in these Real World React+Redux tutorials when it comes to forms. For example, say I have a page with reviews on it. So there's a Component that handles editing a review. Where does the state for all the form inputs go? Does it go in the Redux store? If it does, then every time the user types a letter you get an event, which goes walking backward through the component tree until it…

This is something that tripped me up when I first started learning Redux too, and it would be great if there were more articles about what to do with the bits that don't really fit nicely into the model.

My personal take is that the Redux state tree is for managing state that other components care about, i.e. if this changes, does something outside of this need to know? In the form example, there are few cases where we care about what is being typed as it is being typed (maybe autocomplete). We generally only care about the complete input. This could even be taken to the next level and we could say we only really care about the contents of a form once it has been submitted.

To think about it another way,: what state would we like to keep if the page was refreshed? Many UI elements may contain state we don't really care about outside of the component, such as drop-down menus, accordions, etc. There are things which constitute global state, and there are things that really are just local state. Why make them global?

Ultimately, the goal of Redux is to make reasoning about the state of an application easier, and to encourage better architecture. If pushing certain bits of state into the tree makes this harder, there's no reason to try to force it to fit the pattern.

I'm sure there are good arguments for why everything should be in the global state, but I just haven't found it to be practically beneficial.

Re: A SoundCloud client in React and Redux

#39
post #22

There seems to be a big blind spot in these Real World React+Redux tutorials when it comes to forms. For example, say I have a page with reviews on it. So there's a Component that handles editing a review. Where does the state for all the form inputs go? Does it go in the Redux store? If it does, then every time the user types a letter you get an event, which goes walking backward through the component tree until it…

For basic forms, where you're not doing something weird, why would intermediate form state need to live in Redux? Local React state seems best for that.

Are there any cons to this approach? For me, having to implement setstate manually, not having full undo/redo/time travel debugging as an option/not being able to rehydrate the app from any state snapshot, along with the cognitive overhead of keeping state in sync in two places, one of which is mutable, are the big downsides.

Re: A SoundCloud client in React and Redux

#40
post #19

There seems to be a big blind spot in these Real World React+Redux tutorials when it comes to forms. For example, say I have a page with reviews on it. So there's a Component that handles editing a review. Where does the state for all the form inputs go? Does it go in the Redux store? If it does, then every time the user types a letter you get an event, which goes walking backward through the component tree until it…

Everyone basically just uses Redux Form ( http://redux-form.com/5.2.5/ ) as near as I can tell; it really works well. It basically works as per your first guess: Everything goes in the store. And no, it doesn't really have any performance or efficiency issues. Try it out and see. :)

While a super cool and important project, it's a ton of work to integrate into an app when you have maybe 3 sets of radio buttons to deal with, such as when doing an incremental migration refactoring.
Post reply on HN