Real time markdown rendering while streaming OpenAI API response

Does anyone know of any libraries that can be used to render OpenAI API streaming responses?

I have react-markdown set up to display the messages in markdown once they are fully received, but I can’t find a solution for rendering them in real-time as they are streamed.

This is how bettergpt did it:

a naive way would be to just redraw the message when you get an update.