Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support component that does not import React but that still have props

See original GitHub issue

I have a component that does not import React at all (not required)

// @flow
import { Component } from "react"

type Props = {
  initialState?: State,
  children: (
    state: State,
    setState: (state: State) => void,
  ) => ReactElement,

type State = {
  [key: string]: any,

export default class Playground extends Component<void, Props, State> {

  state: State;

  constructor(props: Props) {
    this.state = (typeof props.initialState === "object")
      ? props.initialState
      : {}

  handleStateChange(state: State) {

  render(): ReactElement {
    return (
        (state) => this.handleStateChange(state),

When I use this component, I got a “React is not defined” error. I suspect that babel-plugin-flow-react-proptypes replace the Props by React.PropTypes even if React is not in the current scope.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

brigandcommented, Jun 5, 2016

I think I already fixed it. Pushed as 0.5.0.

Let me know if it works for you.

brettstackcommented, Sep 29, 2016

@MoOx it looks like you have some solution for defining children - can you comment over at #48? What does your ReactElement type look like?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How passing props to component works in React
Master how to pass props (properties) to components in React with this useful beginner's guide, including demo code.
Read more >
You don't always need to import React - DEV Community ‍ ‍
In this case, React object is not used anywhere so you can leave out the import statement (but still is a valid component)....
Read more >
Use shouldComponentUpdate() to let React know if a component's output is not affected by the current change in state or props. The default...
Read more >
Can't import react component into a gatsby starter component
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: ...
Read more >
How To Customize React Components with Props
Your custom components can use props to display data or use the data ... props do not match the type the code will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found