Deprecated: Smarty::_getTemplateId(): Implicitly marking parameter $template as nullable is deprecated, the explicit nullable type must be used instead in /export/sd206/www/jp/r/e/gmoserver/1/0/sd0297310/charobo.com/libs/Smarty.class.php on line 1048

Deprecated: Smarty_Internal_Data::getTemplateVars(): Implicitly marking parameter $_ptr as nullable is deprecated, the explicit nullable type must be used instead in /export/sd206/www/jp/r/e/gmoserver/1/0/sd0297310/charobo.com/libs/sysplugins/smarty_internal_data.php on line 193

Deprecated: Smarty_Internal_Data::_mergeVars(): Implicitly marking parameter $data as nullable is deprecated, the explicit nullable type must be used instead in /export/sd206/www/jp/r/e/gmoserver/1/0/sd0297310/charobo.com/libs/sysplugins/smarty_internal_data.php on line 203

Deprecated: Smarty_Internal_Template::__construct(): Implicitly marking parameter $_parent as nullable is deprecated, the explicit nullable type must be used instead in /export/sd206/www/jp/r/e/gmoserver/1/0/sd0297310/charobo.com/libs/sysplugins/smarty_internal_template.php on line 149

Deprecated: Smarty_Resource::source(): Implicitly marking parameter $_template as nullable is deprecated, the explicit nullable type must be used instead in /export/sd206/www/jp/r/e/gmoserver/1/0/sd0297310/charobo.com/libs/sysplugins/smarty_resource.php on line 175

Deprecated: Smarty_Resource::source(): Implicitly marking parameter $smarty as nullable is deprecated, the explicit nullable type must be used instead in /export/sd206/www/jp/r/e/gmoserver/1/0/sd0297310/charobo.com/libs/sysplugins/smarty_resource.php on line 175

Deprecated: Smarty_Resource::populate(): Implicitly marking parameter $_template as nullable is deprecated, the explicit nullable type must be used instead in /export/sd206/www/jp/r/e/gmoserver/1/0/sd0297310/charobo.com/libs/sysplugins/smarty_resource.php on line 199

Deprecated: Smarty_Template_Source::load(): Implicitly marking parameter $_template as nullable is deprecated, the explicit nullable type must be used instead in /export/sd206/www/jp/r/e/gmoserver/1/0/sd0297310/charobo.com/libs/sysplugins/smarty_template_source.php on line 158

Deprecated: Smarty_Template_Source::load(): Implicitly marking parameter $smarty as nullable is deprecated, the explicit nullable type must be used instead in /export/sd206/www/jp/r/e/gmoserver/1/0/sd0297310/charobo.com/libs/sysplugins/smarty_template_source.php on line 158

Deprecated: Smarty_Internal_Resource_File::populate(): Implicitly marking parameter $_template as nullable is deprecated, the explicit nullable type must be used instead in /export/sd206/www/jp/r/e/gmoserver/1/0/sd0297310/charobo.com/libs/sysplugins/smarty_internal_resource_file.php on line 28

Deprecated: Smarty_Internal_Resource_File::buildFilepath(): Implicitly marking parameter $_template as nullable is deprecated, the explicit nullable type must be used instead in /export/sd206/www/jp/r/e/gmoserver/1/0/sd0297310/charobo.com/libs/sysplugins/smarty_internal_resource_file.php on line 101
CDNを使ってReact.jsを動かす手順|初心者から学ぶReact.js入門

CDNを使ってReact.jsを動かす手順

CDNとはContent Delivery Networkの略で、WebサイトやWebアプリケーションのコンテンツをユーザーに配信するためのネットワークです。

CDNでReact.jsを動かすメリット

CDNを使うと、Node.jsなどをPCにインストールせずにReact.jsを使ったWebサイトやWebアプリケーションを開発することができます。Node.jsがよくわからない方にとっては、この方法でReact.jsを手っ取り早く動かすのが1番スムーズかもしれません。

ただし、本番環境でReact.jsのCDNを使うのは、動作パフォーマンスの面からオススメしません。

CDNを設置する手順

React.jsではJSXという書き方でプログラムのコードを書きますが、これがHTMLではもちろん動きません。そこで、React.js用の2つのCDNと、JSXをJavaScriptに翻訳するBabelというプログラムのCDN、計3つのscriptタグを設置するのがポイントになります。

<!DOCTYPE html>
<html>
	<head>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.1.0/umd/react.production.min.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.1.0/umd/react-dom.production.min.js"></script>
		<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
	</head>
	<body>
		<div id="root"></div>
		<script type="text/babel">
			const App = () => (
				<div>Hello World</div>
			);

			ReactDOM.render(<App />, document.getElementById("root"));
		</script>
	</body>
</html>