Skip to content

Instantly share code, notes, and snippets.

export default ({ onChange, sessionId }) => {
const onChangeStablize = useStableCallback(onChange)
useEffect(() => {
fetch(`/api/v1/session/${sessionId}`)
.then(async (response) => {
if (response.status === 200) {
const data = await response.json()
onChangeStablize(data)
}
})
const [page, setPage] = useState({ pageCurrent: 1, pageTotal: 1 })
// The reference of page will change only when the value of pageCurrent or pageTotal changes.
const semaPage = useSemantic(page)
...
export default () => {
const [state, setState] = useState({
foo: 0,
bar: 1,
})
const foo = state.foo
useEffect(() => {
...do something with foo...
const cb = useCallback((a) => {
//use dep a
...
return (b) => {
// use dep b
...
}
}, [])
const fetchProduct = async (productId) => {
const response = await fetch('http://myapi/product' + productId); // Uses productId prop
const json = await response.json()
return json
}
function ProductPage({ productId }) {
const [product, setProduct] = useState(null)
useEffect(() => {
function ProductPage({ productId }) {
const [product, setProduct] = useState(null)
const fetchProduct = useCallback(async (productId) => {
const response = await fetch('http://myapi/product' + productId); // Uses productId prop
const json = await response.json()
setProduct(json)
}, [])
useEffect(() => {
function ProductPage({ productId }) {
const [product, setProduct] = useState(null)
async function fetchProduct () {
const response = await fetch('http://myapi/product' + productId); // Uses productId prop
const json = await response.json()
setProduct(json)
})
useEffect(() => {
const obj1 = {
name: 'jack'
}
const obj2 = {
name: 'jack'
}
const str1 = 'jack'
const str2 = 'jack'
export default ({ onDataUpdate, id }) => {
useEffect(() => {
fetch(`/api/v1/session/${id}`)
.then((res) => {
onDataUpdate(res)
})
}, [onDataUpdate, id])
}