Simple React Patterns
lucasmreis.github.io
Simple React Patterns
1–10 of 87 posts
Re: Simple React Patterns
#2Re: Simple React Patterns
#3Part of me is sad that Javascript has now been made OOP, after a majority of efforts pushing the balance towards becoming more and more functional (e.g. PureScript) only a few years ago.
Re: Simple React Patterns
#4Beyond those, my React/Redux links list has sections on "React Component Patterns" [2] and "React Component Composition" [3], with links to many additional articles on these topics.
[1] https://github.com/vasanthk/react-bits
[2] https://github.com/markerikson/react-redux-links/blob/master...
[3] https://github.com/markerikson/react-redux-links/blob/master...
Re: Simple React Patterns
#5Part of me is sad that Javascript has now been made OOP, after a majority of efforts pushing the balance towards becoming more and more functional (e.g. PureScript) only a few years ago.
React explicitly discourages using inheritance with components, instead promoting composing components together like functions. You're also encouraged to keep them stateless if possible, so they create the same output for the same input. I'll need some convincing that functional programming is on its way out in JavaScript.
Re: Simple React Patterns
#6Earlier quoted context omitted.
React explicitly discourages using inheritance with components, instead promoting composing components together like functions. You're also encouraged to keep them stateless if possible, so they create the same output for the same input. I'll need some convincing that functional programming is on its way out in JavaScript.
Yeah, but why did they switch from `React.createClass({..})` to the class syntax? Classes are terrible in JS, they're not even native JS, it doesn't fit in JS. This change alone has brought more and more OO JS code.
Also, the functional syntax has mixins and other ways to combine objects or share code, I think that would be harder to do with classes, which make them even less flexible.
Re: Simple React Patterns
#7Take this example:
const withDagobah = ({
LoadingViewComponent,
ErrorViewComponent,
PlanetViewComponent
}) =>
class extends React.Component {
…
};
In a language with proper generics, you’d write this instead: class Dagobah extends React.Component {
…
}
And then you’d clearly have an object of type Dagobah, easy to inspect and debug. (And Dagobah = Dagobah, whereas withDagobah(A, B, C) ≠ withDagobah(A, B, C).)(I’ll ignore the topic of type erasure.)
Re: Simple React Patterns
#8How does the pervasive use of higher-order functions affect debugging? Take this example: const withDagobah = ({ LoadingViewComponent, ErrorViewComponent, PlanetViewComponent }) => class extends React.Component { … }; In a language with proper generics, you’d write this instead: class Dagobah extends React.Component { … } And then you’d clearly have an object of type Dagobah , easy to inspect and debug. (And Dagobah…
Re: Simple React Patterns
#9Earlier quoted context omitted.
React explicitly discourages using inheritance with components, instead promoting composing components together like functions. You're also encouraged to keep them stateless if possible, so they create the same output for the same input. I'll need some convincing that functional programming is on its way out in JavaScript.
Yeah, but why did they switch from `React.createClass({..})` to the class syntax? Classes are terrible in JS, they're not even native JS, it doesn't fit in JS. This change alone has brought more and more OO JS code.
Now that ES6 classes are actually part of the language, there's no reason for the React team to continue maintaining their own class-like implementation. They can defer that to the language itself. This also enables better use of standardizing tooling around the JS language.
Re: Simple React Patterns
#10Earlier quoted context omitted.
Yeah, but why did they switch from `React.createClass({..})` to the class syntax? Classes are terrible in JS, they're not even native JS, it doesn't fit in JS. This change alone has brought more and more OO JS code.
In React v0.13 https://reactjs.org/blog/2015/03/10/react-v0.13.html , they claimed the reason for the switch is because the `class` syntax is for "more flexibility." What can you do with the `class` syntax that you can't do with the functional syntax? Furthermore, you can generate React code much easier with the functional syntax than with the class syntax. Also, the functional syntax has mixins and other ways to com…