React JavaScript

Passing a Parameter to a Function

This JavaScript program demonstrates how to pass a parameter to a function in React.

FunctionParamReact.html

<!DOCTYPE html>
	<html>
	<head>
		<title>XoaX.net's Javascript React</title>
		<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
		<script async src="https://ga.jspm.io/npm:es-module-shims@1.7.0/dist/es-module-shims.js"></script>
		<script type="importmap">
			{
				"imports": {
					"react": "https://esm.sh/react?dev",
					"react-dom/client": "https://esm.sh/react-dom/client?dev"
				}
			}
		</script>
		<script type="text/babel" data-type="module" src="FunctionParamReact.js"></script>
	</head>
	<body>
		<div id="idRoot"></div>
	</body>
</html>

FunctionParamReact.js

// This requires a web service.
import React, { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';

function Welcome({ name }) {
	return <h1>Welcome to {name}!</h1>;
}

let App = function App() {
	// Calls the function with the parameter
	return <Welcome name="XoaX.net" />
}

const root = createRoot(document.getElementById('idRoot'));
// App Specifies where to put the return value.
root.render(
	<StrictMode>
		<App />
	</StrictMode>
);
 

Output

 
 

© 2007–2026 XoaX.net LLC. All rights reserved.