Skip to content

Instantly share code, notes, and snippets.

@hiro08gh
hiro08gh / index.js
Created September 1, 2019 01:42
suspense lazyを使ったpage単位のコード分割
import React, {Suspense} from 'react';
import {Switch, Route} from 'react-router-dom';
import paths from '../constants/path';
const App = React.lazy(() => import('../pages/App'));
const Root: React.FC = () => (
<>
<Suspense fallback={null}>
<Switch>
@hiro08gh
hiro08gh / README.md
Last active September 16, 2019 00:13
The tools I use

Development enviroment

  • macOS
  • ubuntu 18.04

Editor & terminal

  • neovim
  • iterm2

Web apps

  • GitHub – code repositories
@hiro08gh
hiro08gh / App.tsx
Created August 29, 2019 09:01
フォームの値を変更するcustom hooks
import React from 'react';
import useInputValue from './hooks/useInputValue';
const App: React.FC = () => {
const {value, onChange} = useInputValue('');
return (
<div className="App">
Test
<input {...value} onChange={onChange}/>
{value}
@hiro08gh
hiro08gh / list.tsx
Created August 27, 2019 23:39
Next.jsのgetInitialPropsのhooks
import { NextFunctionComponent, NextContext } from 'next'
// Define what an individual item looks like
interface IDataObject {
id: number,
name: string
}
// Define the props that getInitialProps will inject into the component
interface IListComponentProps {
@hiro08gh
hiro08gh / _app.tsx
Created August 27, 2019 23:20
Nextの_app.tsxを関数コンポーネントに書き換え
import React from 'react';
import App, {Container} from 'next/app';
function MyApp({Component, pageProps}) {
return (
<Component {...pageProps} />
);
}
MyApp.getInitialProps = async ({Component, ctx}) => {
@hiro08gh
hiro08gh / globals.js
Created August 26, 2019 23:49
styled-componentsのglobal style
import styledNormalize from 'styled-normalize';
import { createGlobalStyle } from 'styled-components';
export default createGlobalStyle`
${styledNormalize}
@font-face {
font-family: 'Lato';
src: url('/fonts/LatoLatin-Semibold.woff') format('woff');
}
@hiro08gh
hiro08gh / index.md
Last active August 26, 2019 09:01
javascriptの優良リンク
@hiro08gh
hiro08gh / Button.js
Last active August 26, 2019 21:10
switchでbuttonタイプを分ける
import React from "react";
import ButtonBase from "./Base";
function Button(props) {
switch (props.Type) {
case "largeFull":
return (
<ButtonBase fullWidth buttonHeightPc={48} fontSizePc={16} {...props}>
{props.children}
</ButtonBase>
@hiro08gh
hiro08gh / react-app-env.d.ts
Created August 26, 2019 06:13
create-react-appでprocess.envを扱いたい場合の型拡張
/// <reference types="react-scripts" />
declare namespace NodeJS {
interface ProcessEnv {
readonly NODE_ENV: 'development' | 'production' | 'test';
readonly GOOGLE_ANALITYCS: string;
}
}
@hiro08gh
hiro08gh / Canvas.tsx
Created August 26, 2019 02:41
hooksでcanvas属性を扱う
import React, {useEffect, useRef} from 'react';
function Canvas() {
const canvasRef = useRef(null);
const getContext = (): CanvasRenderingContext2D => {
const canvas: any = canvasRef.current;
return canvas.getContext('2d');
};