React
cannot appear as a child of Warning

前端 未结 2 617
有刺的猬
有刺的猬 2021-01-17 22:02

I am getting the following warnings in a React component:

The related code is the following:

import React, { PropTypes } from \'react\';
imp         


        
2条回答
  •  再見小時候
    2021-01-17 22:52

    If you need to return several elements and can't have a wrapper (such as in this case), you have a new option as of React 16.2. Fragments:

    
      {params.data.firstName} 
      {params.data.lastName} 
    
    

    Or, you might be able to simplify it as:

    <>
      {params.data.firstName} 
      {params.data.lastName} 
    
    

    The fragments won't resolve to any HTML element, so the s will be direct children of your .

提交回复
热议问题