Going through some code on github I found the following unit test:
it('should update links when link href update', async () => {
let anchorInstance = null;
function AnchorUpdate({ href }) {
return (
<Anchor
ref={c => {
anchorInstance = c;
}}
>
<Link href={href} title="API" />
</Anchor>
);
}
const wrapper = mount(<AnchorUpdate href="#API" />);
I don't understand what the braces are for, are they converting the parameter to an object?
The keys are to do
destructuring
, an object arrives at that function and it needs to be left alone with the property ,href
you can read something about it here or here . For example, if you pass an object:{data: [], success: true, href: 'probando'}
and you need onlyhref
then put{ href }
in the parameter of your function, if you needed to capture its value but call the variable with another name it would be{ href: miHref }
and with this youmiHref
would have the value of the propertyhref
that came in the parameter of that function.