简体   繁体   中英

JSX dynamic component - Unknown prop

I'm trying to render components after dynamically determining their name and I'm getting this

Unknown prop ent on <resultComponent> tag. Remove this prop from the element.

The offending code, within another component

  <ul>
    {this.state.results.map(entity => {
      var resultComponent = null;
      var key = null;

      if (entity instanceof ProjectModel) {
        resultComponent = ProjectResult;
        key = "p";
      } else {
        resultComponent = UserResult;
        key = "u";
      }

      return <resultComponent key={key + entity.id} ent={entity}/>;
    })}
  </ul>

You should rename your component, so it begins with a uppercase letter.

The JSX tag name convention (lowercase names refer to built-in components, capitalized names refer to custom components).

So, <ResultComponent key={key + entity.id} ent={entity}/>; should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM