0

I'm trying to add "{ "text" :" to the beginning, and "}" to the end of the string.

I've been looking around and playing with different versions of what's below

{'{ "text" : "'+{...propName.props}+'" }'}

Is it even possible to append to a spread attribute?

Adding more information to what Im trying to achieve

An empty propsName.props passes down to an <input type="text"/>

<input
      type="text"
      className="SCSSstuff"
      disabled={loading}
      placeholder="Demo Text"
      autoComplete="off"
      ref="someRef"
      tabIndex={3}
      {...propsName.props}  //<---- 'User Text' gets defined here
      />

I need to pass that down to a hidden input

<input
      type="hidden"
      disabled={loading}
      {...propsName.props} //<-- I need this output to be { "text" : "User Text" }
      />
freshcoder
  • 1
  • 1
  • 2

1 Answers1

0

If your props contain user entered value then it should be some primitive type.

You could use template string to achieve the desired result.

const propName = {
    props: 'hey'
}
const templateString = `{ text: ${ propName.props } }`
console.log(templateString) // { text: hey }

Hope that helps!!!

tarzen chugh
  • 10,561
  • 4
  • 20
  • 30