DEV Community

Discussion on: Why I let React go!

Collapse
 
sabbin profile image
Sabin Pandelovitch • Edited

You can try to move to functional components instead. You will not get rid of JSX but it will certainly resolve some issues that you listed:

this

Will not be a problem anymore

Nested states

I had another problem here. Not as the fact that it doesn't work, you can have nested states as you specified. The problem wast that render was not triggered on the nested changes... the component does not render again due to the fact that it checks only the first level of the state object, it's not a deep comparison.

With hooks you can split the nested object to multiple objects and have only one level.

const [myInfo, setMyInfo] = useState({ 
    firstName: 'Adnan',
    lastName: 'Babakan'
});

const [otherStateObj, setOtherStateObj] = useState({});
JSX

Conditional rendering... you can have conditional rendering in multiple ways done, it's just a matter of choice

either just put the conditional in the render function

return(
    loggedIn ? <Home/> : <Auth/>
)

either create a separate conditional and use it in the render

const content = {
   true: <Home/>,
   false: <Auth/>
}[loggedIn]

return content;
//or
return (
   <OtherComponent>
        {content}
   </OtherComponent>
)

You can also go further and wrap the content in a useMemo hook to not create it every time but only if isLogged has changed...

There a lot of ways of going on with this... I think that going to functional with hooks solves some issues, of course everybody have their own opinion, this is just mine on this case.

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

Hi
All these things you mentioned are amazing and thanks for sharing these with me.
But still I believe these are ways to workaround and still very complicated than other frameworks like Vue.

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)