Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You do not embed your code into some “React project”. You call React however you see fit. Sure, you pass it some callbacks, but it doesn’t make React stop being a library.


I might have always used React wrong, I don't call React but embed my code into React like so (syntactic sugar aside)

    class HelloWorld extends React.Component {
      render() {
         return (
           --- my code here start ---
           <div>Hello World!</div>
           --- my code here end ---
         );
      }
    }
and React is calling my code with render(), I'm not calling React.

React owns the control flow and the execution loop, which calls your code (hooks, render, ...) as needed.

With a library you own the control flow.


Here is what you typically do if you use vanilla React in Web context from scratch:

1. You define a function (or in your example a class) which calls React.createElement(...) one or more times and returns the result.

2. You set up the initial DOM as needed.

3. You call ReactDOM (another library, separate from React) and give it your function as callback.

4. ReactDOM sets up the main loop that handles updates to DOM when things change.

You can claim that ReactDOM’s reconciler “owns” the flow, but you have to keep in mind that reconciler is not part of React proper, that you are the one who calls it in the first place, and that React does not provide a reconciler of its own or impose any constraints whatsoever on the structure of your project or what you use to render things in the end or where (it could be not even DOM at all).

I imagine most people who think of vanilla React as a framework go with CRA or another template that brings in the boilerplate code, bundler configurations that make JSX magically work, etc., and acts as a sort-of-almost-framework (not a particularly good one, perhaps), which obscures the fact that React itself is merely a very generic library.


"It's not a framework because I say so"

Ok!


No. React calls your code (over and over again). That's a framework.


If using callbacks is what makes it a Web framework then you can call anything a Web framework.

React is a library not even specifically for Web. Angular, however, is a Web framework. It’s up to you if you want to compare the two, but you will not be comparing Web frameworks.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: