I have seen many tutorials and articles which use useState
to store all the records on a state instead of using ReactDOM
or something to add HTML elements.
For example, they keep previous data and merge with new data and after that set in a useState
hook
return [...new Set([...prevBooks, ...res.data.docs.map(b => b.title)])]
I have 2 questions
- Isn't it a performance problem to have all the records in the state and to print it in JSX by map? There may be millions of records.
- If I want to add a React component to the end of a div#ID, what should we do in the pagination?
For example, I have this block code:
<article className="col-sm">
<div className="row client-home-header-post-article-row" id="BlogsPosts">
{posts.entries.map((item) => (
<BlogItem post={item} key={item.id} size={4} />
))}
</div>
</article>
And with an action function like const showMore
, add another <BlogItem post={item} key={item.id} size={4} />
to the bottom of BlogsPosts
ID (like e.append)
I saw this post Append component in React, he suggested without recommending to use ReactDOM.createPortal
, but I tested it like this, and it does not work
ReactDOM.createPortal(
<BlogItem post={item} key={item.id} size={4} />,
document.querySelector("#BlogsPosts")!
)
The posts I saw:
- Append component in React
- Reactjs append an element instead of replacing
- How do you append a React Component to an html element
- How to append React components to HTML element using .append()
- How can I append a React component to an html element i?
- Using document.querySelector in React? Should I use refs instead? How?
- Append Element to an Existing Element React
Thank you in advance