Shane O'Sullivan's technical blog… really ties the room together

Using React types with Flow

Posted by Shane O'Sullivan on March 22, 2018

A little tip for using React types, such as React.Node or React.Element with Flow.  If you import React into a component like

import React from ‘react’;

then Flow will give you the error

Cannot get React.Node because property Node is missing in object type

The fix is to import React as follows

import * as React from ‘react’;

2 Responses to “Using React types with Flow”

  1. JP said

    It’s exactly the same game with TypeScript

  2. Stevan said

    Bad idea, if you don’t have tree shaking, that one could hurt…
    Try this instead :
    import React from ‘react’;
    import type { Node } from ‘react’;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: