「React入門」条件付きレンダーのサンプル

2021年2月17日

使用例

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>React sample</title>
<script src="/react/16.4.0/umd/react.development.js"></script>
<script src="/react-dom/16.4.0/umd/react-dom.development.js"></script>
<script src="/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
<div id="cft"></div>

<script type="text/babel">
function UserGreeting(props) {
  return <h1>Welcome back</h1>;
}

function GuestGreeting(props) {
  return <h1>please login</h1>;
}

function Greeting(props) {
  const isLoggedIn = props.isLoggedIn;
  if (isLoggedIn) {
    return <UserGreeting />;
  }
  return <GuestGreeting />;
}

ReactDOM.render(
  // Try changing to isLoggedIn={true}:
  <Greeting isLoggedIn={false} />,
  document.getElementById('cft')
);
</script>

</body>
</html>

 

 

React.js

Posted by arkgame