in the code below
I want to make the tags variable as Object instead of a list
Like
[
{key1: input tag, key2: input tag2, key3: input tag3},
]
"input tag" has the text which user inputs.
But is such a thing possible?
My current code is below
import React from "react";
const TagsInput = (props) => {
const [tags, setTags] = React.useState([]);
const addTags = event => {
setTags([...tags, event.target.value]);
event.target.value = "";
};
return (
<div className="tags-input">
<input
type="text"
onKeyUp={event => addTags(event)}
placeholder="Press enter to add tags"
/>
</div>
);
};
export default TagsInput;
3
Answers
You can push obj to array like this
this work for me :
If I understood you correctly, you want to store your state data as an object instead of an array.
If that’s the case you can do the following: