LoginSignup
0
0

More than 1 year has passed since last update.

React: SVG の使い方

Last updated at Posted at 2022-06-25

こちらのサンプルに SVG を加えました。
React で jsx を使うサンプル

image.png

index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>React Tutorial</title>
</head>
<body>
    <!-- Reactの描画対象を準備しておく -->
<div id="root"></div>
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/babel-standalone/babel.min.js"></script>
<script type="text/babel" src="main.jsx" defer></script>
</body>
</html>
main.jsx
function App() {
 const str_out = <div>皆さんこんにちは<br />
 今日は良いお天気です<br />
 晴れています<br />
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  <circle cx="30" cy="20" r="10" stroke="cyan" fill="none"/>
  <circle cx="50" cy="20" r="10" stroke="black" fill="none"/>
  <circle cx="70" cy="20" r="10" stroke="red" fill="none"/>
  <circle cx="40" cy="37.32" r="10" stroke="yellow" fill="none"/>
  <circle cx="60" cy="37.32" r="10" stroke="green" fill="none"/>
</svg>
</div>
  return str_out
}

const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(<App/>)

サーバーの起動

http-server

ブラウザーで、http://127.0.0.1:8080 にアクセス
冒頭の画面が出てきます。

参考

Solid.js: SVG の使い方 (TypeScript)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0