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 -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -