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 from "react"; | |
const ToDoList = ({ items }) => { | |
return ( | |
<div> | |
<ul> | |
{items.length | |
? items.map((item) => <li key={item.id}>{item.text}</li>) | |
: null} | |
</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
import React from "react"; | |
const ToDoList = ({ items }) => { | |
return ( | |
<div> | |
<ul> | |
{items.length && items.map(item => <li key={item.id}>{item.text}</li>)} | |
</ul> | |
</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
import React from "react"; | |
const Toggle = () => { | |
const [isActive, setIsActive] = React.useState(false); | |
return ( | |
<button onClick={() => setIsActive(!isActive)}> | |
{isActive ? "Active" : "Inactive"} | |
</button> | |
); |
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 from "react"; | |
const Toggle = () => { | |
const [isActive, setIsActive] = React.useState(false); | |
const toggleActiveState = activeState => () => { | |
setIsActive(activeState); | |
}; | |
return ( |
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 from "react"; | |
const Toggle = () => { | |
const [isActive, setIsActive] = React.useState(false); | |
const toggleActiveState = activeState => () => { | |
setIsActive(activeState); | |
}; | |
return ( |
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 { useState } from "react"; | |
import SelectList from "./SelectList"; | |
const options = ["Apples", "Pears", "Lemons", "Limes"]; | |
function App() { | |
const [selectedValue, setSelectedValue] = useState(options[0]); | |
return ( |
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 { createContext, useState, useContext, useMemo } from "react"; | |
const SelectListContext = createContext(); | |
const SelectList = ({ children }) => { | |
const [isOpen, setIsOpen] = useState(false); | |
const contextValue = useMemo( | |
() => ({ | |
isOpen, |
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 App = () => { | |
const [isModalOpen, setIsModalOpen] = useState(false); | |
return ( | |
<div className="App"> | |
<h1>Try opening the modal</h1> | |
<button onClick={() => setIsModalOpen(true)}>Open the modal</button> | |
{isModalOpen ? ( | |
<Modal> |
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 Modal = ({ children }) => { | |
return ( | |
<div className="Modal"> | |
<div className="Modal-content">{children}</div> | |
</div> | |
); | |
}; | |
const ModalHeader = ({ children }) => { | |
return ( |
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 Modal = ({ header, body, onClose, onConfirm, confirmButtonText }) => { | |
const renderBody = () => { | |
if (typeof body === "string") { | |
return <p>body</p>; | |
} | |
return body; | |
}; | |
return ( |
NewerOlder