D
D
Denoro552018-10-16 02:29:00
React
Denoro55, 2018-10-16 02:29:00

How can I scroll blocks after rendering in React?

I have a chat page that constantly renders new message blocks.

<div className="user-list">
            <ul className="users">
              { this.props.users.map(function(elem,i){
                return <li key={i} className="user-item">{elem}</li>
              })
            }
            </ul>
          </div>

But how can you scroll down the block with messages after drawing new blocks?
element.scrollTop = element.scrollHeight; (I think in this way) well, or another, if there is,
it turns out if you write it in render, then it will scroll before rendering
componentDidMount in general, it will work once after rendering the page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-10-16
@Denoro55

if you write in render, then it will scroll before rendering
componentDidMount in general, it will work once after rendering the page

I heard that there is also some kind of componentDidUpdate - make your scroll in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question