News for hackers. Stuff that matters.
Re:An experienced Javascript developer’s account of learning... by arenaninja on Saturday April 22, 2017 @08:42AM (#14172225)
I don't think the `className` argument sticks. `class` is reserved so you can't use it. It's annoying but not a difficult concept

The other points are valid though. Mobx/Redux seems like a solution for big applications, but what's the alternative for small-to-medium React applications that still need to store state?

I agree I had issues following the snippets (and for one snippet I would definitely have to check MDN to decipher ES6 syntax), but I wonder if that's not an issue of style. Just like you can write PHP inline with HTML and you can write JS with HTML in JSX storing snippets of logic in a variable increases readability.

Re:An experienced Javascript developer’s account of learning... by Bahamut on Saturday April 22, 2017 @11:29AM (#14172977)
The className complaint is a valid complaint - it's a limitation of JSX, which is specific to React here.
Re:An experienced Javascript developer’s account of learning... by epidemian on Saturday April 22, 2017 @05:42PM (#14174986)
> I don't think the `className` argument sticks. `class` is reserved so you can't use it.

But you can use it. JSX nodes get compiled into React.createElement calls with object literals[1], and {class: "foo"} is a perfectly valid object literal in JS, s there's nothing stopping `<div class="foo" />` to get compiled into `React.createElement("div", {class: "foo"})`

In fact, other frameworks that support JSX syntax allow the use of `class` instead of `className`[2], so it's not a limitation of JSX per-se, it's just a design decision on part of React (and an annoying one at that).

[1]: As noted in the first code snippet on the React homepage https://facebook.github.io/react/

[2]: E.g., Mithril https://mithril.js.org/jsx.html#jsx-vs-hyperscript

Re:An experienced Javascript developer’s account of learning... by jazoom on Saturday April 22, 2017 @08:54AM (#14172265)
It's valid. className was a frequent annoyance with React. That's one of the nice things about Vue. I can paste HTML snippets and they just work. I can't say it's the reason I switched, but it was some icing on the cake.
Re:An experienced Javascript developer’s account of learning... by wand3r on Saturday April 22, 2017 @11:19AM (#14172938)
What was the reason?
Re:An experienced Javascript developer’s account of learning... by jazoom on Saturday April 22, 2017 @05:26PM (#14174900)
A few reasons. The render() functions were unweildly. The ecosystem of router/state libraries were in constant incompatible flux. Difficult transition animations. Complex server side rendering setup. Probably some other things I can't remember.
Re:An experienced Javascript developer’s account of learning... by thaiphanvevo on Saturday April 22, 2017 @11:44AM (#14173042)
> what's the alternative for small-to-medium React applications that still need to store state?

I've found that with small React apps, you normally organise each component to be responsible for handling its own state.

If you need a global shared state but your app isn't large enough for Redux then lots of people pass callbacks down to child components as parameters. True story.

Re:An experienced Javascript developer’s account of learning... by rmetzler on Sunday April 23, 2017 @10:18AM (#14178240)
Yes, that's what I do. Managing the global state in the main component, setting up functions to change the state via the update helper [1] and pass these functions down to the dumb components.

[1]: https://facebook.github.io/react/docs/update.html

Re:An experienced Javascript developer’s account of learning... by arcticfox on Saturday April 22, 2017 @08:56AM (#14172272)
Am I doing something wrong on small-to-medium applications by simply using setState? I always worry about this, even if Dan Abramov blessed it.

Sometimes I need some more global stuff, which I have solved in the past using context but I feel like maybe I'll just hook up some small mobX store in the future... Not sure

Re:An experienced Javascript developer’s account of learning... by haukur on Saturday April 22, 2017 @09:05AM (#14172307)
No, you should be fine. If it starts to get painful to pass around props, investigate Redux or MobX rather than using context by hand.
Re:An experienced Javascript developer’s account of learning... by darth_mastah on Saturday April 22, 2017 @11:52AM (#14173074)
I don't see what's wrong with redux for medium/small apps?