Upgrade to Pro — share decks privately, control downloads, hide ads and more …

React学んでみた

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

 React学んでみた

Avatar for Nico_Zetsche

Nico_Zetsche

January 30, 2023

More Decks by Nico_Zetsche

Other Decks in Technology

Transcript

  1. 宣言的な View 出力の性質やあるべき状態を記述してプログラムを構成する宣言型プログラミ ング 例えばReact Elementの記述スタイル <Test name="cat" times="1" />

    のようにどんなデータが表示されるかべきかを記述することで、Reactが表示してくれて、適切なタイミン グで更新もしてくれる。 参照透過性の担保、つまり同じ入力には必ず同じ出力が得られる。 これは、Web Componentsの思想を踏襲している。
  2. React hooksとは クラスコンポーネントでしか扱えなかったstate等を関数コンポーネント で扱えるようになった。 function Example() { // Declare a

    new state variable, which we'll call "count" const [count, setCount] = useState(0); return ( <div> <p>You clicked {count} times</p> <button onClick={() => setCount(count + 1)}> Click me </button> </div>); }
  3. React hooksの副作用(useEffect)を使えば非同期処理もできる const useGetStatus = (code): ReturnValue => { const

    [code, setCode] = useState([]); useEffect(() => { const load = async () => { try { const statusData = await getStatus(code); setCode(statusData); } catch (err) { throw new Error(`'${code}' not exists`); } }; }, [code]);
  4. Context APIとは グローバルで値を保存できる const ThemeContext = React.createContext('light'); const App =

    () => { const theme = useState('light'); return ( <ThemeContext.Provider value={theme}> <ThemedButton/> </ThemeContext.Provider> const ThemedButton = () => { const theme = userContext(ThemeContext); return <Button theme={theme} />; }