Passing in class names to react components

前端 未结 9 760
说谎
说谎 2020-12-23 02:35

I am trying to pass in a classname to a react component to change it\'s style and cannot seem to get working:

class Pill extends React.Component {

  render(         


        
9条回答
  •  遥遥无期
    2020-12-23 03:08

    You can achieve this by "interpolating" the className passed from the parent component to the child component using this.props.className. Example below:

    export default class ParentComponent extends React.Component {
      render(){
        return 
      }
    }
    
    export default class ChildComponent extends React.Component {
      render(){
        return 
    } }

提交回复
热议问题