And React by itself is very simple, you don't even have to use JSX. It's a great templating library, with great documentation and a huge community.
Not true. With Redux you write reams of actions and reducers and other such unnecessary crap in the name of state management, when in fact most client apps don't have state, all they do is fetch data from the server, display it, send updates back to the server.
React used to be a simple lib, now it is getting more and more complicated. Look at the libs I mentioned they are way simpler.
>you don't even have to use JSX
But JSX is the good part of React. You get compile-time checking of your expressions if you use TypeScript and you get syntax coloring, intellisense etc for both HTML and JavaScript.
I agree JSX is very nice. It's one of the best features of React, and another reason React is a great templating lib. My point was you don't need it. React does a lot of other nice things like browser compatibility, event management. If you want a smaller implementation, use preact or some other template lib.
When dealing with React and Redux you are just dealing with functions. You could do everything in pure functions.
You don't have to deal with any of that crap.
The best part of React is DOM diffing and incremental screen update. Obviously this is only useful if your application needs to update screens it previously rendered. In fact I'd argue that React is only useful if you need to incrementally update complex screens, because simple screens can be re-rendered completely and no one will know the difference. Very few applications need to incrementally update complex screens. If your application doesn't have this need you can use simpler technologies that don't have the same "Care and feed" requirements of React, such as UIBuilder: https://github.com/wisercoder/uibuilder
Just because you use pure functions doesn't mean you don't get DOM diffing, that's silly.
But the very fact that we're having this debate is proving my point. React's programming model is unnecessarily complicated. JavaScript + DOM is all you need. The simple libs (each less than 500 lines) I pointed to get you close to this without sacrificing productivity or code maintainability while keeping the programming model simple.
React isn't complicated, you're making out to be.
import React, { useState } from 'react';
export const SetterButton = ({ children, ...rest }) => (
<button type="button" {...rest}>{children}</button>
)
export const BoxComponent = ({ label }) => {
const [value, setValue] = useState(0);
return (
<div style={border: '1px solid black'}>
{label}: {value}
<SetterButton onClick={() => setValue(value + 1)}>+1</SetterButton>
</div>
);
};
Or for a bigger app with many nested components, you can use context: import React, { useState } from 'react';
export const ValueContext = React.createContext();
export const SubComponent = () => (
<div>
<p>
Here's a value:
<ValueContext.Consumer>
{({ value }) => value}
</ValueContext.Consumer>
</p>
<p>
Here's a button:
<ValueContext.Consumer>
{({ setValue, value }) => <button type="button" onClick={() => setValue(value + 1)}>+1</button>}
</ValueContext.Consumer>
</p>
</div>
)
export const App = () => {
const [value, setValue] = useState();
return (
<ValueContext.Provider value={{ value, setValue }}>
Some other stuff goes here.
<SubComponent></SubComponent>
</ValueContext.Provider>
);
}
None of this takes a ton of thought. Just make a file for contexts exports and a root level component with any Providers.