News for hackers. Stuff that matters.
Re:Redux – Not Dead Yet by kabes on Wednesday April 25, 2018 @06:31AM (#16920213)
Straight from the react docs [1]:

  if (isLoggedIn) {
    return <UserGreeting />;
  }
How is that different?

[1] https://reactjs.org/docs/conditional-rendering.html

Re:Redux – Not Dead Yet by winterbe on Wednesday April 25, 2018 @09:11AM (#16921195)
The difference is that the JSX snippet is translated in plain JavaScript which means you can automatically check for syntax errors, type errors (when using TypeScript or Flow) and semantical errors (by writing simple unit tests), whereas the PHP snippet is just a big mess. JSX also runs on clients, servers and mobile devices which is a big plus to me.

This is fine:

  <?php
  if (condition) {
  ?>
  <div>whatever</div>
  <?php
  {
  ?>
this not:

  if (isLoggedIn) {
    return <UserGreeting />;
  {
Re:Redux – Not Dead Yet by dmitriid on Wednesday April 25, 2018 @09:36AM (#16921373)
Re:Redux – Not Dead Yet by tootie on Wednesday April 25, 2018 @06:29PM (#16926904)
This is the official example of using context from the react doc

  function 
   ThemedButton(props) {
     return (
       <ThemeContext.Consumer>
         {theme => (
           <button
             {...props}
             style=. 
   {{backgroundColor: 
   theme.background}}
          />
        )}
      </ThemeContext.Consumer>
    );
  }
I've been writing JavaScript for 15 years and this looks like gibberish to me. There's at least 3 context switches between JavaScript, JSX and CSS. We're abandoning separation of concerns and creating a monstrosity of programming by punctuation.