DEV Community

Writing React with TypeScript

Sebastian Kurfürst on January 02, 2019

Just a quick note today as I stumbled over a a nice GitHub repo: We've made good experiences writing React Applications with TypeScript -- and I j...
Collapse
 
mscharl profile image
Michael Scharl

Just a few weeks ago I migrated a React project from Flow to TypeScript. When I set it up I thought using Flow would be ideal since React and Flow are developed by Facebook and they should be made for each other.

I switched to TypeScript because Flow feels not as strict as TS. It lacks some features that I enjoy about TS such as Enums. When compiling Flow does not throw Errors when you write "invalid" code. TS fails and shouts at me which makes it feel "safer" to use. Maybe I did not use Flow correctly. If so, it's probably not as intuitive as TS.

Collapse
 
skurfuerst profile image
Sebastian Kurfürst

Thanks for your comment :) I did not try out Flow, as it seemed to me more immature than TypeScript. What is important for TS though is to turn on Strict mode IMHO.

All the best, Sebastian

Collapse
 
mscharl profile image
Michael Scharl

That‘s exactly what I experienced!

Good to know that others think the same 😁

Collapse
 
kirillvy profile image
Kirill V

I am migrating from Vue.js to React+TS. So far, the pure JS feel with the typing seems much more complex than Vue's magic and object-based components. Besides the materials you posted, which should save a lot of time, is there anything I can do to make the transition easier?

In particular, I don't understand what the Redux store lets you do you that the context API with higher order components doesn't. Possibly because of my experience with Vuex, which is essentially a higher-order component that provides a context, but has the same structure as a Vue component, with actions and mutations as syntactic sugar.

Collapse
 
skurfuerst profile image
Sebastian Kurfürst

Hey,

I'd suggest that you start without Redux first; as you'll now when you need it. So if you feel the new Context API is enough, then this is perfectly fine (in many applications, it is totally enough).

At a certain (big) scale, switching to Redux makes sense; but you'll notice when you need this :)

All the best,
Sebastian