skip to Main Content

Consider the following data I am getting as a string:
a, b, c are a form of variables that I am importing from a config file as string.

const str = 'a, b, c, d, e, f, g'
{React.createElement(Components[someComponent],{...str})}

What am I doing wrong or what can be changed? Also we can make changes in the config file but it consists of an array of multiple objects.

If there is any way to get the string converted in such format it can solve the problem.

const str = {a, b, c, d, e, f, g};

Then I can simply pass it on.

2

Answers


  1. hi If you want to send as props, your code should be like below

    React.createElement(Components[someComponent], { str: str })

    Login or Signup to reply.
  2. You can do something like this

    const str = "a, b, c, d";
      const props = {};
      str.split(",").forEach((item) => {
        props[item.trim()] = item.trim();
      });
    
    and use
    
    {React.createElement(Components[someComponent], props)}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search