V
V
Vladimir2020-02-11 18:13:26
JavaScript
Vladimir, 2020-02-11 18:13:26

How to integrate click event with block scroll in react?

Good evening. Please tell me how to properly insert scrolling, the idea is this: clicking on the button - scrolling to the beginning of the next block / to the height of the current one, but .. The error is obvious, it cannot find the home element. it has not been created yet, can I somehow postpone it or does react have its own functions to implement this?

Here is what I tried, thanks:

function scroll() {
    return document.querySelector('.textBoxes').scrollTo(0, 400)
}

function createButton(className, text, type) {
    if(type !== String) {
        return (
            <button type={type} className={className} onClick={scroll()}>{text}</button>
        )
    }
    else {
        return (
            <button className={className} onClick={scroll()}>{text}</button>
        )
    }
}


Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shohruh Shaimardonov, 2020-02-11
@joeberetta

Google banned?
SO

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question