This file contains 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 { Store } from "./store"; | |
import Count from "./Count"; | |
//don't connect to store | |
const App = () => { | |
const {actions} = Store | |
return ( | |
<div> | |
<Count /> |
This file contains 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 { createStore, createHook } from "react-global-hook"; | |
const initialState = { | |
counter: 0 | |
}; | |
const actions = ({ setState, getState }) => ({ | |
addToCounter(amount) { | |
const { counter } = getState() |
This file contains 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 { createStore, createHook } from "react-global-hook"; | |
import actions from "../actions"; | |
const initialState = { | |
counter: null | |
}; | |
export const Store = createStore( | |
initialState, |
This file contains 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 actions = ({ setState, getState }) => { | |
increase(store) { | |
const { counter } = getState(); | |
setState({ | |
counter: counter + 1 | |
}); | |
}, | |
decrease(store) { | |
const { counter } = getState(); |
This file contains 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
function App() { | |
const [data, setData] = useState([]); | |
const [query, setQuery] = useState('a query for search'); | |
useEffect(() => { | |
const fetchData = async () => { | |
const result = await axios( | |
`http://hn.algolia.com/api/v1/search?query=${query}`, | |
); | |
This file contains 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
function App() { | |
const [data, setData] = useState([]); | |
const [isLoading, setLoading] = useState(false); | |
const [error, setError] = useState(''); | |
const [query, setQuery] = useState('a query for search'); | |
useEffect(() => { | |
const fetchData = async () => { | |
setLoading(true) | |
try { |
This file contains 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 { useFetching } from "react-concurrent"; | |
const app = () => { | |
const [query, setQuery] = useState('a query for search'); | |
const { data, isLoading, error } = useFetching(() => { | |
const result = await axios( | |
`http://hn.algolia.com/api/v1/search?query=${query}`, | |
); | |
return result.data |