Skip to content

Get Rendered Element Ref (React.createRef()) #115

Closed
@tiberiusferreira

Description

@tiberiusferreira

Hello, I've seen other issues which wanted a similar thing such as #75.

For a project in React I was implementing a chat and I had to "auto-scroll" to the last message when I got a new one. I did this by using:

  messagesEndRef = React.createRef();

  scrollToBottom = () => {
    if (this.messagesEndRef.current != null){
      (this.messagesEndRef.current).scrollIntoView({ behavior: 'smooth' })
    }
  };


  componentDidUpdate(prevProps, prevState, snapshot){
        this.scrollToBottom()
  }

render(){
 <div ref={this.messagesEndRef} />
}

I'm sure there are other use cases for getting a ref to the rendered element.

I think this could be implemented now manually by hooking into the did_mount and manually storing the Node information, but would be nice to see a more ergonomic way of doing it.

I don't have a solution in mind yet, I just wanted to see if this is something Seed would want to implement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    missing functionalityNot quite a bug, but needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions