3

How to import Node (type used by flow), and PureComponent in one line only for code purity.

Lines below don't work:

import type { Node }, { PureComponent } from 'react';
// or
import type { Node, PureComponent } from 'react';

Note: I actually use this

/* @flow */
import { PureComponent } from 'react';
import type { Node } from 'react';

Thanks in advance

Jon Miles
  • 9,605
  • 11
  • 46
  • 66
Made in Moon
  • 2,294
  • 17
  • 21

2 Answers2

3

Try this,

import { type Node, PureComponent } from 'react';

Which works and is clean.

udonmai
  • 41
  • 5
0

As written in the docs mentioned here, for using the named type import, you need to add in addition to the default import.

Again, if you import React with: import React from 'react' you will be able to access React.Component, React.createElement(), React.Children, and other JavaScript values. However, you will not be able to access React.Node, React.ChildrenArray or other Flow types. You will need to use a named type import like: import type {Node} from 'react' in addition to your default import.

Pritish Vaidya
  • 21,561
  • 3
  • 58
  • 76