1

I'm trying to get some values from the JSON array on some http-address. Therefore, when I put from the map in the input field, I got an Object instead of a value. Outside the input field, it works fine.

    <FormGroup>
         <Label for="description">Description</Label>
         <Input type="text" name="description" id="description" value={Object.keys(item.storeByClothes).map(clothes =>{return <p>{item.storeByClothes[clothes].description}</p>})}
           onChange={this.handleChange} autoComplete="description"/>
    </FormGroup>
{Object.keys(item.storeByClothes).map(clothes =>{return <p>{item.storeByClothes[clothes].description}</p>})}

Inside <FormGroup> I got the Object. External is a necessary value. What am I doing wrong?

2
  • 1
    What can you tell us about your <FormGroup>, <Label> and <Input> components? Did you build them? Are they from a library? We'll need that info to know their default behavior with the props you've passed them. Commented Aug 26, 2018 at 16:23
  • I think I had a syntax error. I removed the tags and return - operator, and now work fine. Thanks, your remark has turned my attention to check the code again. Commented Aug 26, 2018 at 16:25

1 Answer 1

1

currently JSX transpiler converts <p>... into React component (object) and then passes it into input as its value. To display variable's content browser calls .toString() method. so finally you see "[Object object]" there. Depending on your needs you need different changes made.

Say if you expect to see HTML markup inside input(like a string) you should make it string(say using template strings):

.map(el => `<p>....`

Or you just should not put it into <input value if you need to see it as live HTML markup

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.