0

hi am reading an example of higher order components for React here

the code snippet is :

function ppHOC(WrappedComponent) {
  return class PP extends React.Component {
    constructor(props) {
      super(props)
      this.state = {
        name: ''
      }
      
      this.onNameChange = this.onNameChange.bind(this)
    }
    onNameChange(event) {
      this.setState({
        name: event.target.value
      })
    }
    render() {
      const newProps = {
        name: {
          value: this.state.name,
          onChange: this.onNameChange
        }
      }
      return <WrappedComponent {...this.props} {...newProps}/>
    }
  }
}

@ppHOC
class Example extends React.Component {
  render() {
    return <input name="name" {...this.props.name}/>
  }
}

so what is the purpose of the @ operator ie @ppHOC class Example is it equivalent to implements???

pgee70
  • 3,707
  • 4
  • 35
  • 41
  • 1
    thanks i will look into the decorator symbol - searching for @ didn't get results where 'at' would have ;-) – pgee70 Nov 07 '16 at 02:05
  • No worries. It's hard to find questions like this that are duplicates. I don't fault you at all for this. I just know that I had seen that question before. – Eli Sadoff Nov 07 '16 at 02:06

0 Answers0