I use flow, so
import * as React from 'react',
But also I use React Hook, like useState.
so how can I import this?
like
import * as React, {useState} from 'react'
or
import * as React from 'react';
import {useState} from 'react';
or some other method?
Hope for better workaround!
You can't import * as React, {useState} from 'react' use an alias to import the whole react and then another entity of it in the same module import.
You can either do:
import * as React from 'react;
and then you can access the useState API within your function like this: React.useState(...)
or
import * as React from 'react';
import {useState} from 'react';
I suggest the former as it's cleaner and better when it comes to modules resolution.
Maybe take a look at this as well: JavaScript Modules
Yeah. Eventually the plan is to change the JSX transform to remove the need for import * altogether.
Most helpful comment
You can't
import * as React, {useState} from 'react'use an alias to import the wholereactand then another entity of it in the same module import.You can either do:
and then you can access the
useStateAPI within your function like this:React.useState(...)or
I suggest the former as it's cleaner and better when it comes to modules resolution.
Maybe take a look at this as well: JavaScript Modules