useEffect
+useEffect
useEffect
+useEffect
{`
@@ -195,7 +199,7 @@
useEffect
+useEffect
{`
@@ -208,7 +212,7 @@
useEffect
+useEffect
{`
@@ -220,7 +224,7 @@
useEffect
+useEffect
{`
@@ -232,7 +236,7 @@
useEffect
+useEffect
{`
@@ -244,7 +248,7 @@
useEffect
+useEffect
{`
@@ -257,7 +261,7 @@
useEffect
+useEffect
{`
@@ -282,4 +286,339 @@
+
+ useContext
+
+
+ useContext
+
+
+ {`
+ import { createContext, useContext, useState } from 'react';
+
+ const AppContext = createContext(null);
+ `}
+
+
+
+
+ useContext
+
+
+ {`
+ import React, { createContext, useContext, useState } from 'react';
+
+ export const AppContext = createContext(null);
+
+ export default function MyApp() {
+ const [someState, setSomeState] = useState('hello');
+ return (
+ <>
+
+
+
+
+ >
+ )
+ }
+ `}
+
+
+
+
+ useContext
+
+
+ {`
+ import React, { useContext, useState } from 'react';
+
+ import {AppContext} from "./MyApp";
+
+ export default function MyComponent() {
+ const appContext = useContext(AppContext)
+ return (
+ {appContext}
+ )
+ }
+ `}
+
+
+
+
+ useContext
+
+
+ {`
+ import React, { useContext, useState } from 'react';
+
+ import {AppContext} from "./MyApp";
+
+ export default function MyComponent() {
+ const appContext = useContext(AppContext)
+ return (
+ {appContext}
+ )
+ }
+ `}
+
+
+
+
+ useReducer
+
+
+ useReducer
+
+
+
+ useReducer
+
+
+ {`
+ import {useReducer} from "react";
+
+ function myReducer(state, action) {
+ if(action.type === "on") {
+ return {
+ data: "Switch on"
+ }
+ } else if(action.type === "of") {
+ return {
+ data: "Switch Off"
+ }
+ }
+ }
+
+ export function MyComponent(props) {
+ const [state, dispatch] = useReducer(myReducer, {});
+
+ function onSwitchToggle(status) {
+ dispatch({
+ type: status
+ })
+ }
+
+ return(
+
+
+
+
+ )
+
+ }
+ `}
+
+
+
+
+ useReducer
+
+
+ {`
+ import {useReducer} from "react";
+
+ function myReducer(state, action) {
+ if(action.type === "on") {
+ return {
+ data: "Switch on"
+ }
+ } else if(action.type === "of") {
+ return {
+ data: "Switch Off"
+ }
+ }
+ }
+
+ export function MyComponent(props) {
+ const [state, dispatch] = useReducer(myReducer, {});
+
+ function onSwitchToggle(status) {
+ dispatch({
+ type: status
+ })
+ }
+
+ return(
+
+
+
+
+ )
+
+ }
+ `}
+
+
+
+
+ useReducer
+
+
+ {`
+ import {useReducer} from "react";
+
+ function myReducer(state, action) {
+ if(action.type === "on") {
+ return {
+ data: "Switch on"
+ }
+ } else if(action.type === "of") {
+ return {
+ data: "Switch Off"
+ }
+ }
+ }
+
+ export function MyComponent(props) {
+ const [state, dispatch] = useReducer(myReducer, {});
+
+ function onSwitchToggle(status) {
+ dispatch({
+ type: status
+ })
+ }
+
+ return(
+
+
+
+
+ )
+
+ }
+ `}
+
+
+
+
+ useReducer
+
+
+ {`
+ import {useReducer} from "react";
+
+ function myReducer(state, action) {
+ if(action.type === "on") {
+ return {
+ data: "Switch on"
+ }
+ } else if(action.type === "of") {
+ return {
+ data: "Switch Off"
+ }
+ }
+ }
+
+ export function MyComponent(props) {
+ const [state, dispatch] = useReducer(myReducer, {});
+
+ function onSwitchToggle(status) {
+ dispatch({
+ type: status
+ })
+ }
+
+ return(
+
+
+
+
+ )
+
+ }
+ `}
+
+
+
+
+ useReducer
+
+
+ {`
+ import {useReducer} from "react";
+
+ function myReducer(state, action) {
+ if(action.type === "on") {
+ return {
+ ...state,
+ data: "Switch on",
+ }
+ } else if(action.type === "of") {
+ return {
+ ...state,
+ data: "Switch Off"
+ }
+ }
+ }
+
+ export function MyComponent(props) {
+ const [state, dispatch] = useReducer(myReducer, {});
+
+ function onSwitchToggle(status) {
+ dispatch({
+ type: status
+ })
+ }
+
+ return(
+
+
+
+
+ )
+
+ }
+ `}
+
+
+
+
+ useReducer
+
+
+ {`
+ import {useReducer} from "react";
+
+ function myReducer(state, action) {
+ if(action.type === "on") {
+ return {
+ ...state,
+ data: "Switch on",
+ }
+ } else if(action.type === "of") {
+ return {
+ ...state,
+ data: "Switch Off"
+ }
+ }
+ }
+
+ export function MyComponent(props) {
+ const [state, dispatch] = useReducer(myReducer, {});
+
+ function onSwitchToggle(status) {
+ dispatch({
+ type: status
+ })
+ }
+
+ return(
+
+
+
+
+ )
+
+ }
+ `}
+
+
+
--
cgit v1.2.3