This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState } from "react"; | |
| import PropTypes from "prop-types"; | |
| export const UserCard = ({ user }) => { | |
| return ( | |
| <ul> | |
| <li>{user.name}</li> | |
| <li>{user.age}</li> | |
| <li>{user.email}</li> | |
| </ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const UserContainer = () => { | |
| const [user, setUser] = useState(null); | |
| // do some apiCall here | |
| return ( | |
| <div> | |
| {user ? <UserCard user={user} /> : 'No data available'} | |
| </div> | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const NestedComponent = () => { | |
| // ... | |
| return ( | |
| <> | |
| {!isLoading ? ( | |
| <> | |
| <h2>Some heading</h2> | |
| <p>Some description</p> | |
| </> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const NestedComponent = () => { | |
| // ... | |
| if (isLoading) return <Spinner /> | |
| return ( | |
| <> | |
| <h2>Some heading</h2> | |
| <p>Some description</p> | |
| </> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const UserCard = ({ user }) => { | |
| const getUserRole = () => { | |
| const { roles } = user; | |
| if (roles.includes('admin')) return 'Admin'; | |
| if (roles.includes('maintainer')) return 'Maintainer'; | |
| return 'Developer'; | |
| } | |
| return ( | |
| <ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const getUserRole = (roles) => { | |
| if (roles.includes('admin')) return 'Admin'; | |
| if (roles.includes('maintainer')) return 'Maintainer'; | |
| return 'Developer'; | |
| } | |
| const UserCard = ({ user }) => { | |
| return ( | |
| <ul> | |
| <li>{user.name}</li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const CustomInput1 = ({ onChange }) => { | |
| return ( | |
| <Input onChange={e => { | |
| const newValue = getParsedValue(e.target.value); | |
| onChange(newValue); | |
| }} /> | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const CustomInput2 = ({ onChange }) => { | |
| const handleChange = (e) => { | |
| const newValue = getParsedValue(e.target.value); | |
| onChange(newValue); | |
| }; | |
| return ( | |
| <Input onChange={handleChange} /> | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState } from 'react'; | |
| const Form = () => { | |
| const [name, setName] = useState(''); | |
| const handleChange = e => { | |
| setName(e.target.value); | |
| } | |
| const handleSubmit = () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState } from 'react'; | |
| const Form = () => { | |
| const [name, setName] = useState(''); | |
| const handleChange = e => { | |
| setName(e.target.value); | |
| } | |
| const handleSubmit = e => { |