Skip to content

Instantly share code, notes, and snippets.

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

Hamed Esmaili theham3d

🏠
Working from home
View GitHub Profile

Keybase proof

I hereby claim:

  • I am theham3d on github.
  • I am theham3d (https://keybase.io/theham3d) on keybase.
  • I have a public key whose fingerprint is 410B 6B14 F87C B767 CE31 3B2B 2A4C 27B1 D95B C268

To claim this, I am signing this object:

@theham3d
theham3d / getDerivedStateFromError.js
Created November 1, 2018 22:37
getDerivedStateFromError Example
import React , { Component } from 'react';
class CatchError extends Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error) {
// if something happens this will update state so the next render will show our fallback UI.
return { hasError: true };
@theham3d
theham3d / useReducerExample.js
Created November 1, 2018 10:23
useReducer Example
import React , { useReducer } from 'react';
const initialState = {count: 0};
const yourReducer = (state, action) => {
switch (action.type) {
case 'reset':
return initialState;
case 'increment':
return {count: state.count + 1};
case 'decrement':
@theham3d
theham3d / useContextExample.js
Created November 1, 2018 08:54
useContext Example
import React , { useContext } from 'react';
import { AppContext } from './App';
const MyComponent = props => {
const value = useContext(AppContext);
return <h1>{value}</h1>;
}
export default MyComponent;
@theham3d
theham3d / useEffectExample.js
Created November 1, 2018 08:26
useEffect Example
import React, { Component } from 'react';
class ClassComponent extends Component {
componentDidMount() {
fetchSomething();
}
render() {
return <div>شیب، بام؟</div>;
}
@theham3d
theham3d / useStateExample.js
Created October 31, 2018 16:37
useStateExample
import React , { useState } from 'react';
const MyCounter = props => {
const [count, setCount] = useState(0);
//you can use useState as much as you want
return (
<div>
<h1>{count}</h1>
<button onClick={() => setCount(count + 1)}>Click me</button>
@theham3d
theham3d / rcContextType.js
Created October 31, 2018 10:36
rcContextType
import React , { Component } from 'react';
import { AppContext } from './App';
class MyComponent extends Component {
componentDidMount() {
let value = this.context;
/* و قص علی هذا */
}
componentDidUpdate() {
let value = this.context;
@theham3d
theham3d / rcLazyExample.js
Created October 31, 2018 10:11
lazy example
import React , { lazy , Suspense } from 'react';
const ShomalComponent = lazy(() => import('./ShomalComponent'));
const MyComponent = props => (
<Suspense fallback={<div>Loading...</div>}>
<ShomalComponent />
</Suspense>
);
export default MyComponent;
@theham3d
theham3d / rcMemoExample.js
Last active October 31, 2018 09:10
memo example
import React , { memo } from 'react';
const ShomalComponent = props => (
<div>
<p>?چرا در شمال ایران سقف اکثر خانه ها را شیب دار میسازند</p>
</div>
);
export default memo(ShomalComponent)