Skip to content

Instantly share code, notes, and snippets.

View chriskavanagh's full-sized avatar

Chris Kavanagh chriskavanagh

  • Home Office
  • Roanoke, VA - U.S.A.
View GitHub Profile
@chriskavanagh
chriskavanagh / compositionContext.txt
Last active February 20, 2024 02:09
composition instead of context
import { useState } from "react";
const Container = ({ children }) => <div>{children}</div>;
const AddOneButton = ({ setCounter }) => (
<div>
<button onClick={() => setCounter((v) => v + 1)}>Add One</button>
</div>
);
@chriskavanagh
chriskavanagh / react-context.txt
Last active February 20, 2024 02:11
react context
import { useState, createContext, useContext } from "react";
const CounterContext = createContext(null);
const CounterContextProvider = ({ children }) => (
<CounterContext.Provider value={useState(0)}>
{children}
</CounterContext.Provider>
);
import React from "react";
import { Formik } from "formik";
import * as Yup from "yup";
//import Error from "./Error";
import styled from "styled-components";
const Form = styled.form`
width: 100%;
max-width: 600px;
margin: 25px auto;
import React from "react";
import { Formik, Field, ErrorMessage, Form } from "formik";
import * as Yup from "yup";
//import Error from "./Error";
import styled from "styled-components";
const Button = styled.button`
background: gray;
color: navy;
width: 30%;
function App() {
const size = useWindowSize();
return (
<div>
{size.width}px / {size.height}px
</div>
);
}
@chriskavanagh
chriskavanagh / hamburger.html
Last active November 10, 2019 05:55
Hamburger Button HTML/CSS
<div class="nav-icon">
<div></div>
</div>
https://codepen.io/chriskavanagh/pen/zYYjZGq
@chriskavanagh
chriskavanagh / reduce.js
Created August 14, 2019 15:40
Using Reduce To Create Object
Add refs to each element in list using reduce, by creating obj.
list = [
{
id: "a",
firstname: "Robin",
lastname: "Wieruch",
year: 1988
},
{
import React, { Component } from "react";
import Input from "./common/Input";
export default class LoginForm extends Component {
state = {
username: "",
password: "",
errors: {}
};
import React, { Component } from "react";
export default class LoginForm extends Component {
state = {
username: "",
password: ""
};
handleSubmit = e => {
e.preventDefault();
import React, { Component } from "react";
export default class LoginForm extends Component {
state = {
username: "",
password: ""
};
handleSubmit = e => {
e.preventDefault();