Flowtype now react-only? In 0.53 above example generates error: "identifier React. Could not resolve name"
// import React from 'react'
function A(
props: {a: string;}
) {
return <div>{props.a}</div>
}
<A a='123' />
How to use power of flowtype in jsx pure components without importing react?
Flow has support for the @jsx pragma, but it doesn't work on TryFlow.
See https://github.com/facebook/flow/blob/master/newtests/jsx_pragma/test.js
Ok, this workaround works:
//@flow
// @jsx Bar
function Bar<Props>(component: ((props: Props, ...x: any[]) => any) | string, props: Props, ...childs: any[]) {}
function A(
props: {a: string;}
) {
return <div>{props.a}</div>
}
<A a="1" />
But how to do same without placing @jsx in each file and without importing Bar?
@zerkalica Why do you need it? It won't work without importing React anyway.
@vkurchatkin
class Counter {
@mem value = 0
}
export function CounterView(
_: {},
{counter}: {
counter: Counter
}
) {
return <div>
<div>
Count: {counter.value}
</div>
<button onClick={() => { counter.value++ }}>Add</button>
<button onClick={() => { counter.value = ('error': any) }}>Gen error</button>
</div>
}
CounterView.deps = [{counter: Counter}]
I guess the easiest way would be do declare global React.
Do you now how to do that?
I try:
// flow-typed/react-stub.js
// @flow
import R from 'react'
declare var React: R
// test.js
//@flow
function A(
props: {a: string;}
) {
return <div>{props.a}</div>
}
<A a={1} />
flow does not check errors:
$flow check
Found 0 errors
Try this: declare var React: $Exports<'react'>;
It works, thank you.
@vkurchatkin's solution works great, but are there any docs for the @jsx pragma? @samwgoldman
I was using this trick to work with flow and vue.
https://github.com/wemake-services/wemake-vue-template/blob/c203e751f9d9ed9cfc411a4cdf56d35fe8a2dda7/template/client/components/ActionBar.vue#L3
Since 0.76 it is not working any more. https://github.com/wemake-services/wemake-vue-template/pull/645
Are there any ideas how to fix it now?
@sobolevn, @nucleartide I recommend opening a new issue
Still no solution https://github.com/facebook/flow/issues/6626
@mrkev I wonder why it is recommended to open a new issue if this one actually was never resolved?
Recommending declare var React: $Exports<'react'>; sounds like a joke.
I found this clean way to work for me, in your .flowconfig file add react.runtime=automatic under [options].
Most helpful comment
Try this:
declare var React: $Exports<'react'>;