Skip to content

Non-component functions that return JSX #512

Closed
@perrin4869

Description

@perrin4869

react-router allows you to override the createElement function when rendering a route component. For example:

<Router history={browserHistory} createElement={createElement}>{...}</Router>

const createElement = (Component, props) => (
  props.route.dependencies = props.route.dependencies || {};
  return React.createElement(Component, { ...props, ...props.route.dependencies });
);

This createElement function is not a component (a component is a pure function of the props, but in this case it has two parameters, the component and the props), however, eslint recognizes it as one and demands that the propTypes be defined. Maybe the component recognition as specified here: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md can be narrowed down to functions with only one parameter.

Edit: the error I get is 'route' is missing in props validation (react/prop-types)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions