DEV Community

loading...

Discussion on: React vs Vue: Compare and Contrast

jwp profile image
John Peters

First time I saw Jsx I thought it was the coolest thing since chewing gum! I like it actually.

Hooks tie into their state stuff, I don't like react's state stuff. Why? Because I don't see the advantage of farming off state to another thing. Internal variables to the component or even observables are closer to the metal in my opinion. In fact, an Observable could easily mimic the React state stuff. Right?

import React, { useState } from 'react';

function Example() {
  // Declare a new state variable, which we'll call "count"
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}
Thread Thread
miketalbot profile image
Mike Talbot • Edited

Yeah it's the diffing/refreshing algorithm. See I don't farm it off much - only perhaps when it's a local thing that isn't part of the real application state. So imagine my app is editing documents, I'd use useState to capture the rename of something, in a dialog, in case the user cancels. The rest of the time my React looks like this:

    return <Bound target={someRoot} refresh={refresh}>
        <BoundTextField field="name"/>
        <BoundTextField field="age" transformOut={convertToMinMaxNumber(0, 100)}/>
        <BoundAutocomplete options={choices} field="mode" label="Choose your mode"/>
    </Bound>

Those BoundXYZ things come from a neat little wrapper that interprets the specific components value and events - a one liner
for all of the MaterialUI components I use and the ability to return to
the core if I need it.

Refresh up there is basically an internal trigger using a useState() hook to trigger rendering and perform other actions.

Thread Thread
jwp profile image
John Peters

What's your thoughts on this? I haven't tried it in React , but this is how I do it in Angular. Angular automatically detects changes to bound elements.

import React, { useState } from 'react';

function Example() {
  // Declare a new state variable, which we'll call "count"
  let count = 0;
  onCountClicked =()=>{
  count++;
  }

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => onCountClicked()}>
        Click me
      </button>
    </div>
  );
}
Thread Thread
miketalbot profile image
Mike Talbot

Yeah I've always liked Angular. We didn't choose it for our current project because we found it hard to "late load" unknown classes for injection into a template - which is a very specific requirement.

If I were to put the point for React it would be that its fairly explicit about what it's doing - it's very mechanical and low level - though having looked at an article of Fiber recently - I guess it isn't THAT low level.

I need something to feel like bound data to be happy, so I make my own. I dislike Redux because your logic is in a huge pile somewhere else. That never worked for the way I reason out problems.