Search code examples
reactjsformattinguser-input

How to allow user formatting in React app?


I have a React app where a user can type something into textbox, click 'submit' and then the text appears somewhere.

I want to add functionality which will allow the user to format the text. Just like you can do here on SE when asking questions. For example I want the below input to be shown as bold.

<b>bold</b>

How can I achieve this? Or where to look for this kind of thing?


Solution

  • If you want to enable the same functionality you get in stack overflow, then I think the one way to achieve this would be allowing the user to input markdown and converting that to HTML. This is a library that could help with that: marked

    Freecodecamp has a markdown previewer as one of their projects, so if you want to check out some examples, you could probably find hundreds of different implementations: https://www.freecodecamp.org/forum/t/build-a-markdown-previewer/198715