Skip to content

Instantly share code, notes, and snippets.

View ohansemmanuel's full-sized avatar

Ohans Emmanuel ohansemmanuel

View GitHub Profile
// 🐢 custom hook - name starts with "use" (useMedium)
useMedium(() => {
const URI = "https://some-path-api";
// 🦄 custom hook can use any of the default
// React hooks - this is NOT compulsory.
useEffect(() => {
fetch(URI)
},[])
})
function CounterHooks() {
const [count, setCount] = useState(0);
const [time, setTime] = useState(new Date())
// 🐢 look here.
useEffect(() => {
console.log("useEffect first timer here.")
}, [count])
function CounterHooks() {
const [count, setCount] = useState(0);
const [time, setTime] = useState(new Date())
const handleClick = () => {
setCount(count + 1);
setTime(new Date())
}
return (
function CounterHooks() {
const [count, setCount] = useState(0);
const handleClick = () => {
setCount(count + 1);
}
return (
<div>
<h3 className="center">
import React, { Component } from 'react';
class Counter extends Component {
constructor() {
super();
this.state = {
count: 1
};
}
<!DOCTYPE html>
<head>
<style>
header {
background-image: paint(checker);
}
</style>
</head>
...
for (let y = 0; y < geom.height / size; y++) {
for (let x = 0; x < geom.width / size; x++) {
const color = colors[(x + y) % colors.length];
ctx.beginPath();
ctx.fillStyle = color;
ctx.rect(x * size, y * size, size, size);
ctx.fill();
}
...
for (let y = 0; y < geom.height / size; y++) {
for (let x = 0; x < geom.width / size; x++) {
}
}
...
// declare the custom paint.
class CheckerPaint {
paint (ctx, geom, styleMap) {
const colors = ["#f15278", "#fff"];
const size = 32;
for (let y = 0; y < geom.height / size; y++) {
for (let x = 0; x < geom.width / size; x++) {
// declare the custom paint.
class CheckerPaint {
paint (ctx, geom, styleMap) {
const colors = ["#f15278", "#fff"];
const size = 32;
}