SolidJSS
SolidJSโ€ข3y agoโ€ข
6 replies
Grahf

I don't like refs

Not really a solidJS question but there are smart people here. If there's a rule against this I will remove this post.

I am storing a bunch of refs in an array like this:
<p
ref={(el) => setRefs((p) => [...p, el])}
.....>
Stuff From Database
</p>

The resulting array of refs have worked fine for what I've used them for so far. Each <p> element is the result of a value pulled from a database.

But what I just implemented is the ability to search the database and get back a subset of the <p> elements.

The goal is to be able to click on each item in the subset that's returned from the search and .scrollIntoView the corresponding <p> element in the main page.

If I was doing this with ids I would just give each <p> element an id of the primary key from the database. When the user searches each of their search results will also have the primary key from the database and I could just getElementById the element with the id of what the user clicked on and .scrollIntoView to it. That's how I imagine it in my head.

Not sure how do to that with a ref. I could check the textContent of each ref in the array of refs and see if it matches the textContent of what the user clicked on and then scrollIntoView that ref?
Was this page helpful?