How do I make a script tag render all the time in react

41 Views Asked by At

I have given a

tag from a software company that makes online reservation for restaurants. normally you just paste the script tag in a wordpress article. But now i build my website with vite-React and after reloading, the Button for reservation disappears.

How would i fix that are there ways to rerender the Button ?

2

There are 2 best solutions below

0
Nilesh Pal On

You can try putting it in a main component. if this doesn't resolve please share you code over here which will be more helpful to resolve it efficiently

0
Raghu On

To achieve more control and maintainability, we can use the react-helmet library. Install it using npm:

npm install react-helmet

Now, let's create a React component that utilizes React Helmet

import { Helmet } from 'react-helmet';

function ScriptRenderer() {
  return (
    <div>
      <Helmet>
        <script>
          {`
            console.log('This script runs all the time with React Helmet!');
          `}
        </script>
      </Helmet>
    </div>
  );
}

export default ScriptRenderer;