Skip to content

Instantly share code, notes, and snippets.

View hosseinmd's full-sized avatar
🏠
Working from home

Hossein Mohammadi hosseinmd

🏠
Working from home
  • Freelance
  • Iran
View GitHub Profile
@hosseinmd
hosseinmd / React-Concurrent-example.js
Last active November 5, 2020 19:32
React-Concurrent example
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
@hosseinmd
hosseinmd / CommonFetchingData2.js
Last active November 3, 2020 18:03
A common way for Fetching data with hooks
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 {
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}`,
);
import React from "react";
import { createStore, createHook } from "react-global-hook";
const initialState = {
counter: 0
};
const actions = ({ setState, getState }) => ({
addToCounter(amount) {
const { counter } = getState()
@hosseinmd
hosseinmd / App.js
Last active January 10, 2020 13:50
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 />
@hosseinmd
hosseinmd / actions.js
Last active June 30, 2020 22:26
example of react-global-hook actions
const actions = ({ setState, getState }) => {
increase(store) {
const { counter } = getState();
setState({
counter: counter + 1
});
},
decrease(store) {
const { counter } = getState();
import { createStore, createHook } from "react-global-hook";
import actions from "../actions";
const initialState = {
counter: null
};
export const Store = createStore(
initialState,