This file contains 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"; | |
import { useFormik } from "formik"; | |
function App() { | |
const formik = useFormik({ | |
initialValues: { | |
name: "", | |
email: "", | |
}, | |
onSubmit: (values) => { |
This file contains 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, { useContext } from 'react'; | |
import { UserContext } from './App'; | |
function Header() { | |
const user = useContext(UserContext); | |
return <span>{user.email}</span>; // "my@email.com" | |
} |
This file contains 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'; | |
export function useCounter() { | |
const [count, setCount] = useState(0); | |
const decrement = () => setCount(count - 1); | |
const increment = () => setCount(count + 1); | |
return { | |
count, | |
decrement, | |
increment, |
This file contains 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, { Fragment } from 'react'; | |
const user = { | |
email: 'my@email.com', | |
}; | |
export const UserContext = React.createContext(); | |
function App() { | |
return ( |
This file contains 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, { useReducer } from 'react'; | |
const initialState = { count: 0 }; | |
function reducer(state, action) { | |
switch (action.type) { | |
case 'INCREMENT': | |
return {count: state.count + 1}; | |
case 'DECREMENT': | |
return {count: state.count - 1}; |
This file contains 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'; | |
function App() { | |
const [name, setName] = useState(""); | |
const [email, setEmail] = useState(""); | |
const onSubmit = () => { | |
// do something with `${name}` and `${email}` | |
}; |
This file contains 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
test('can open accordion items to see the contents', () => { | |
const hats = {title: 'Favorite Hats', contents: 'Fedoras are classy'} | |
const footware = { | |
title: 'Favorite Footware', | |
contents: 'Flipflops are the best', | |
} | |
render(<Accordion items={[hats, footware]} />) | |
expect(screen.getByText(hats.contents)).toBeInTheDocument() | |
expect(screen.queryByText(footware.contents)).not.toBeInTheDocument() | |
userEvent.click(screen.getByText(footware.title)) |
This file contains 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
test('setOpenIndex sets the open index state properly', () => { | |
const wrapper = mount(<Accordion items={[]} />) | |
expect(wrapper.state('openIndex')).toBe(0) | |
wrapper.instance().setOpenIndex(1) | |
expect(wrapper.state('openIndex')).toBe(1) | |
}) | |
test('Accordion renders AccordionContents with the item contents', () => { | |
const hats = {title: 'Favorite Hats', contents: 'Fedoras are classy'} | |
const footware = { |
This file contains 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
function describe(description, callback) { | |
console.log(description); | |
callback(); | |
} | |
function it(description, callback) { | |
console.log(description); | |
callback(); | |
} |
This file contains 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
describe("booleans", () => { | |
it("false === false", () => { | |
expect(false).toBe(false); | |
}); | |
it("true === true", () => { | |
expect(true).toBe(true); | |
}); | |
}); |
NewerOlder