Uncaught TypeError: tags.join is not a function.
P粉729436537
P粉729436537 2023-07-28 13:59:53
0
1
508
<p>I have a page with multiple tags stored in an array. I want to edit the page and when trying to load the tag array into TagsInput I get the following error message: </p> <pre class="brush:php;toolbar:false;">Uncaught TypeError: tags.join is not a function</pre> <p>Here is the code snippet associated with this error: </p> <pre class="brush:php;toolbar:false;">import { TagsInput } from "react-tag-input-component"; const UpdatePage = () => { const [tags, setTags] = useState(""); const tagsString = tags.join(", "); // Fetching tags from backend and storing into setTags setTags(<some_code_for_axios_get>) return( <div> <FormControl fullWidth margin="normal"> <TagsInput label="Tags" size="small" value={tagsString} onChange={setTags} placeHolder="Type your tag and press enter" /> </FormControl> </div> ) }</pre> <p>Also tried the following and got the error message that n.map is not a function: </p> <pre class="brush:php;toolbar:false;"><div className="tags"> {tags.length ? tags.map((type, i) => ( <TagsInput key={i} label="Tags" size="small" value={i} onChange={setTags} placeHolder="Type your tag and press enter" /> )) : <TagsInput label="Tags" size="small" value={tags} onChange={setTags} placeHolder="Type your tag and press enter" /> } </div></pre> <p>Using the following code, I can see the data in the console: </p> <pre class="brush:php;toolbar:false;">tags.forEach((element) => { console.log(element); });</pre> <p><br /></p>
P粉729436537
P粉729436537

reply all(1)
P粉533898694

Tags are not an array, they are a string, according to this line:

const [tags, setTags] = useState("");

No matter what happens setTags(<some_code_for_axios_get>), the first render, tags will be ""

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template