Home > Blockchain >  insert variables in react-markdown
insert variables in react-markdown

Time:12-31

I have a text in markdown and I want to display it in my react-app with variables.

I tried this way :

<ReactMarkdown
   children={contentMd}
   renderers={{
     someElement: {
     instanceLabel: label,
     sessionName: test,
     mail: emailSupport,
     adresse: adressePostale,
                  },
             }}
 />

and in my text in markdown I refer the variables like that :

outil de gestion par {{instanceLabel}}

But it doesn't work...

Does someone has a solution?

thanks.

CodePudding user response:

contentMd is a string, not JSX. You need to interpolate variables, for example this way:

<ReactMarkdown
  children={`outil de gestion par ${instanceLabel}`}
  {...props}
/>

Or like so:

<ReactMarkdown
  {...props}
>
  {`outil de gestion par ${instanceLabel}`}
</ReactMarkdown>

CodePudding user response:

I solved my problem.

Like you said Tymek, contantMd is a string so i used the function replace(), thats'all !!

Thanks for your reading

  • Related