Skip to content

Instantly share code, notes, and snippets.

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>
module ArticlesHelper
def published_class(article)
case article.publish_flag
when :draft
"article--draft"
when :published
"article--published"
when :waiting
"article--waiting"
end
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AllAndAny
{
class Program
{
<!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'/>
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);
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>
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);
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);
}
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
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) {