Skip to content

Instantly share code, notes, and snippets.

View matheusml's full-sized avatar

Matheus Lima matheusml

View GitHub Profile
import React from "react";
import { useFormik } from "formik";
function App() {
const formik = useFormik({
initialValues: {
name: "",
email: "",
},
onSubmit: (values) => {
import React, { useContext } from 'react';
import { UserContext } from './App';
function Header() {
const user = useContext(UserContext);
return <span>{user.email}</span>; // "my@email.com"
}
@matheusml
matheusml / App.jsx
Last active February 11, 2021 19:16
import React, { Fragment } from 'react';
const user = {
email: 'my@email.com',
};
export const UserContext = React.createContext();
function App() {
return (
@matheusml
matheusml / App.jsx
Last active February 11, 2021 19:16
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,
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};
import React, { useState } from 'react';
function App() {
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const onSubmit = () => {
// do something with `${name}` and `${email}`
};
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))
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 = {
describe("booleans", () => {
it("false === false", () => {
expect(false).toBe(false);
});
it("true === true", () => {
expect(true).toBe(true);
});
});
function describe(description, callback) {
console.log(description);
callback();
}
function it(description, callback) {
console.log(description);
callback();
}