J
J
jenya77712022-02-26 19:16:29
React
jenya7771, 2022-02-26 19:16:29

How to trigger an event in React when a component is fully or partially displayed on the user's screen?

Hello, I have a list of notifications in the form of a tile, and I need to mark notifications as read when they are completely or 85 percent displayed on the user's screen.

How can this be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Johnny Sins, 2022-02-28
@jpeg_man

You can change the state as soon as the component is mounted on the page. For example, as soon as the user calls the component with the notification tile, change the state: setIsChecked(true).
Create your own stateful hook and use useEffect to subscribe to changes to props or other dependencies . Then call this hook in the notification tile component and work with the state.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question