JSX
APIããã¨ã©ã¼ã®æãæ¹è¡ã³ã¼ãä»ãã®æååãè¿ã£ã¦ããã®ã§ãæ¹è¡ã <br> ã«å¤æãã¦åºåãããã£ãã®ã¡ã¢ ä¾ãã°ãããªæååãæ¹è¡ããã¦è¡¨ç¤ºãããã const msg = "æå®®ãã¡ã\né§ç¢ããã\nç´«å¹è"; ã¿ã°ãå ¥ã£ã¦ãã¦ãæååã¯æååã¨ãã¦åºåããã æ¹â¦
å±æ©ç®¡çã JSXå ã§ã³ã³ãã¼ãã³ããåºãåããããã¨ãã¦ããã£ãã®ã§ã¡ã¢ ãã¡ã ã£ãã³ã¼ã function App( isAdmin ) { return ( <> {isAdmin? ( <AdminMain /> <AdminAside /> ) : ( <Main /> <Aside /> )} ); } ã¨ãã£ã¿ã¼ã®ã·ã³ã¿ãã¯ã¹ãã¤ã©ã¤ãã§æ¬¡ã®ãããªã¨ã©ã¼ã表示ããã¦ãã Left side of </aside></main></adminaside></adminmain>â¦
ãããªã® function Label(props) { // label ã§è¡¨ç¤ºããè¦ç´ ã親ã³ã³ãã¼ãã³ãã§æå®ãããï¼ return ( <label htmlFor={props.htmlFor}>{ â¯â¯â¯â¯ }<label> ); } function Input(props) { return ( <> <Label htmlFor={props.id}>æ¨ã</Label> <input id={props.id} defaultValue={props.dafaultValue} /> ); } <Label /> ã³ã³ãã¼ãã³ããå¥ã«ä½ã£ã¦ããã¦ãåè¦ç´ ã¯HTMLã¿ãâ¦</label></label></label>
HTMLã§æã è¦ããããã¤ã Non-Breaking Space æä¸ã§æãè¿ããããããªãèªå¥ãç¹ãæã«ä½¿ãç¹æ®æåã JavaScript 㧠ãå«ã¾ããHTMLãæ±ãæã®ãã©ãã ã³ã³ãã¼ãã³ãæ代ã®æ¨ä»ã ã¨JSXã¨ãJavaScriptå ã«HTMLãæ¸ããããããã¨â¦
React ã®ã¢ããªã§ä¾ãã°ç·¨éã¢ã¼ãã®æã«ã¯ãã£ã¼ã«ãã§ãããã§ãªãæã¯ããã¹ãã表示ãããªã©ãæ¡ä»¶ã«ãã£ã¦è¡¨ç¤ºãå¤ãããæãªã© JSX å ã§åå²ãããããå ´åã¨ãã ãµã¨æã£ãã JSXã®ä¸ã§ifæ使ãããå ´åã£ã¦ä½ãã¹ã¿ã³ãã¼ããªãã ããï¼JSXã®ä¸ã§ {â¦
Reactã®JSXã§ã¯ã©ã¹åãä»ããæã«å¤æ°ã¨åºå®å¤ãªæååãä¸ç·ã«ä½¿ãããã¨ã ã³ã¬ã¯ãã¾ããããªã return ( <button className="btn btn-${btnState}">BUTTON</button> ); æååçµåãã function Button() { const [btnState, setBtmState] = useState('primary'); return ( <button className={'btn btn-' + btnState}>BUTTON</button> ); } ãã³ãã¬ã¼ãæ§æ â¦
Reactã®JSXã§ã³ã¡ã³ããæ¸ãæ¹æ³ã®ã¡ã¢ JSX Comment JSXã®{ }ã®ä¸ã¯JavaScriptãåä½ããã®ã§{ }ã§å²ã£ã¦ã³ã¡ã³ããæ¸ããã¨ãã§ãã {/* ä¸è¡ã³ã¡ã³ã */} {/* è¤æ°è¡ ã³ã¡ã³ã */} // ã使ããã{ }ã®éãã¿ã°ã®åã«æ¹è¡ãå¿ è¦ã {// ä¸è¡ã³ã¡ã³ã } æ¹è¡â¦
Reactã®JSXã§è¤æ°ã®ã¿ã°ãè¿ãã³ã³ãã¼ãã³ããä½ãããæ JSXã¯ã«ã¼ãã1ã¤ã®ã¿ã°ã§ãªãã¨ã¨ã©ã¼ã«ãªã ä¾ãã¢ã¬ã ãã©ãããã¯ã¨ã©ã¼ã«ãªã function ListData() { // ãããã®æ¹è£ ã«è¤æ°ã®ã¿ã°ããã¨ã¨ã©ã¼ã«ãªã return ( <li>æå®®ãã¡ã</li> <li>é§ç¢ããã</li> <li>ç´«å¹è</li> â¦