[react] default props value

1384 단어 ReactReact

React에서는 props의 value를 따로 쓰지 않으면 boolean으로 보게 되어 있다.
(html5에서는 특정 attribute만 boolean을 갖는다.)

Default Props

class App extends React.Component {
  render() {
    return <MyComponent hasButton/>;
  }
}
// MyComponent내에서 this.props.hasButton은 true가 된다.

Ref

Docs: https://reactjs.org/docs/jsx-in-depth.html#props-default-to-true
Html5: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes#boolean_attributes

좋은 웹페이지 즐겨찾기