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'; | |
import {render} from 'react-dom'; | |
import {useIncrementer} from './useIncrementer'; | |
function IncrementerApp(){ | |
const {count, increment} = useIncrementer(); | |
return <div> | |
<button onClick={increment}>The Button</button> | |
<p>The button has been pressed {count} times</p> | |
</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
module ArticlesHelper | |
def published_class(article) | |
case article.publish_flag | |
when :draft | |
"article--draft" | |
when :published | |
"article--published" | |
when :waiting | |
"article--waiting" | |
end |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace AllAndAny | |
{ | |
class Program | |
{ |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
</head> | |
<body> | |
<input type='text'/> |
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'; | |
import {render} from 'react-dom'; | |
function useWindowWidth(){ | |
const [width, setWidth] = React.useState(window.innerWidth); | |
React.useEffect(() => { | |
function listener(){ | |
setWidth(window.innerWidth); | |
} | |
window.addEventListener('resize', listener); |
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 root = document.getElementById('react-root'); | |
const userData = { | |
name: 'Joel Shinness', | |
email: '[email protected]', | |
hobbies: ['Mandolin', 'Sushi', 'Writing Games'], | |
imgUrl: 'http://joelshinness.com/assets/img/avatars/avatar.jpg' | |
} | |
const jsxExpr = <div> | |
<h1> |
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, {Component, useState, useEffect} from 'react'; | |
import {render} from 'react-dom'; | |
// This represents getting a name resource from the internet. | |
// Quite slowly, might I add. | |
function getNameFromAjax(){ | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
resolve("Mahmoud"); | |
}, 5000); |
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'; | |
import {render} from 'react-dom'; | |
// The container component manages state, passing data and actions to a presenter. | |
class IncrementerContainer extends React.Component { | |
constructor(props){ | |
super(props); | |
this.state = {count: 0}; | |
this.increment = this.increment.bind(this); | |
} |
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, {useState, useEffect} from 'react'; | |
import {render} from 'react-dom'; | |
function CanvasDemo(){ | |
// The ref maintains a link to the canvas element. | |
const canvasRef = React.useRef(); | |
const [point, setPoint] = React.useState([20, 20]); | |
// This draws a rectangle on the canvas |
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, {useState, useEffect} from 'react'; | |
import {render} from 'react-dom'; | |
function Timer({doneNow}){ | |
const [remainingMilliseconds, setRemainingMilliseconds] = useState(300000); | |
useEffect(() => { | |
const fiveMinutesFromNow = +(new Date()) + 5 * 1000; | |
const intervalIdx = setInterval(() => { | |
const diff = fiveMinutesFromNow - new Date(); | |
if(diff <= 0) { |