I have done lots of reading online and just cant get destructuring into my head, well sort of.
//before destructuring
function me(details){
console.log('My name is ' + details.name + ' and I work for ' + details.company);
}
//after destructuring
function me({ name, company }){
console.log('my name is ' + name + ' and i work for ' + company);
}
me({
name: 'Rich',
age: 34,
city: 'London',
company: 'Google'
})
I've written this and this makes sense but one thing I dont get is the following in react.
if you do this:
export default ({ name }) => <h1>Hello {name}!</h1>;
<Hello name="CodeSandbox" />
why cant i do this:
export default ( name ) => <h1>Hello {name}!</h1>;
removing the {} in the function parameter?
if someone sees what im doing wrong please can they explain this?
im used to functions like so:
functionA (a) => { // do something with the parameter a }
not sure about the curlys {} inside the parameters
propsobject to the component -{ name: "asdf" }. To get the name, you need to destructure it.<Hello name="CodeSandbox" />is passed to the function something likeyourFunction({name:"CodeSandbox" })