I'm reading about unknown-prop warnings in react, particularly because I'm using the react-bootstrap package and have stumbled upon them there.
i've read that: 'To fix this, composite components should "consume" any prop that is intended for the composite component and not intended for the child component', on here:
https://gist.github.com/jimfb/d99e0678e9da715ccf6454961ef04d1b
and an example is given for how the spread operator can be used to pull variables off props, and put the remaining props into a variable.
the example code:
function MyDiv(props) {
const { layout, ...rest } = props
if (layout === 'horizontal') {
return <div {...rest} style={getHorizontalStyle()} />
} else {
return <div {...rest} style={getVerticalStyle()} />
}
}
Here is what the PROBLEM is: In the example given, I don't understand what the '...rest' in this code here stands for. I get that the '...' = spread syntax, but where did the word 'rest' come from and what does it stand for?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…