javascript - React - dynamic properties from strings -


in test suit, trying generate components props dynamically, end components so:

<button primary /> <button secondary /> 

currently, bit stuck:

  [     'primary',     'secondary'   ].foreach((buttontype) => {     it(`should render '${buttontype}' button`, () => {       const button = mount(<button {...buttontype}>click me</button>); // incorrect - not work       // rest of test omitted     });   }); 

any appreciated.

you should replace cardtype buttontype in function parameter given foreach.

then, should use following inside test:

const dynamicprops = { [buttontype]: true }; <button {...dynamicprops} /> 

some elements have been omitted idea. when pass prop without explicit definition, mean someprop={true}, in above case have use primary or whatever property of object, value of true.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -