_script_ – React
_script_ – React
v19
<script>
The built-in browser <script> component lets you add a script to
your document.
Reference
<script>
Usage
Reference
<script>
https://react.dev/reference/react-dom/components/script 1/7
20/02/2025, 18:32 <script> – React
Props
async : a boolean. Allows the browser to defer execution of the script until
the rest of the document has been processed — the preferred behavior
for performance.
crossOrigin : a string. The CORS policy to use. Its possible values are
anonymous and use-credentials .
https://react.dev/reference/react-dom/components/script 2/7
20/02/2025, 18:32 <script> – React
React can move <script> components to the document’s <head> and de-
duplicate identical scripts.
To opt into this behavior, provide the src and async={true} props. React
will de-duplicate scripts if they have the same src . The async prop must be
true to allow scripts to be safely moved.
React will ignore changes to props after the script has been rendered.
(React will issue a warning in development if this happens.)
React may leave the script in the DOM even after the component that
rendered it has been unmounted. (This has no effect as scripts just
execute once when they are inserted into the DOM.)
Usage
React will de-duplicate scripts that have the same src , inserting only one of
them into the DOM even if multiple components render it.
https://react.dev/reference/react-dom/components/script 3/7
20/02/2025, 18:32 <script> – React
Show more
Note
When you want to use a script, it can be beneficial to call the preinit
function. Calling this function may allow the browser to start
https://react.dev/reference/react-dom/components/script 4/7
20/02/2025, 18:32 <script> – React
To include an inline script, render the <script> component with the script
source code as its children. Inline scripts are not de-duplicated or moved to
the document <head> .
function Tracking() {
return (
<script>
ga('send', 'pageview');
</script>
);
}
Show more
https://react.dev/reference/react-dom/components/script 5/7
20/02/2025, 18:32 <script> – React
PREVIOUS
<meta>
NEXT
<style>
uwu?
Describing the UI
Adding Interactivity
Managing State
Escape Hatches
Community More
Acknowledgements Terms
https://react.dev/reference/react-dom/components/script 6/7
20/02/2025, 18:32 <script> – React
https://react.dev/reference/react-dom/components/script 7/7