Skip to content

Instantly share code, notes, and snippets.

@xgqfrms-GitHub
Last active September 6, 2017 05:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgqfrms-GitHub/5bbf8672e41ddd08dc28d6a882c72283 to your computer and use it in GitHub Desktop.
Save xgqfrms-GitHub/5bbf8672e41ddd08dc28d6a882c72283 to your computer and use it in GitHub Desktop.
jscomplete & stackoverflow

jscomplete & stackoverflow

https://stackoverflow.com/questions/28452358/what-is-the-meaning-of-this-props-in-reactjs#

https://jscomplete.com/repl/

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

const props = {
    name: "xgqfrms",
    age: 23,
    country: "China"
};

const Test = (props) => {
  return(
    <div
        name={props.name}
        age={props.age}
        country={props.country}>
        Content Here
        <ul>
          <li>name={props.name}</li>
          <li>age={props.age}</li>
          <li>country={props.country}</li>
        </ul>
    </div>
  );
};

ReactDOM.render(
    <div>
        <Test {...props}/>
        <hr/>
        <Test 
            name={props.name}
            age={props.age}
            country={props.country}
        />
    </div>
    , mountNode
);
@xgqfrms-GitHub
Copy link
Author

const props = {
    name: "xgqfrms",
    age: 23,
    country: "China"
};

const Test = (props) => {
  return(
    <div
        name={props.name}
        age={props.age}
        country={props.country}>
        Content Here
        <ul>
          <li>name={props.name}</li>
          <li>age={props.age}</li>
          <li>country={props.country}</li>
        </ul>
    </div>
  );
};

class TestDemo extends React.Component {
    render() {
        const {name, age, country} = {...this.props};
        // const {name, age, country} = this.props;
        return (
          <div
              name={name}
              age={age}
              country={country}>
              Content Here
              <ul>
                <li>name={props.name}</li>
                <li>age={props.age}</li>
                <li>country={props.country}</li>
              </ul>
          </div>
        );
    }
}

ReactDOM.render(
    <div>
        <Test {...props}/>
        <hr/>
        <Test 
            name={props.name}
            age={props.age}
            country={props.country}
        />
        <hr/>
        <TestDemo {...props}/>
    </div>
    , mountNode
);

@xgqfrms-GitHub
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment