enum What {
animal,
person
}
type AnimalProps = {
what: What.animal;
name: string;
};
type PersonProps = {
what: What.person;
age: number;
};
type ComponentProps = AnimalProps | PersonProps;
// если в zipEntry - картинка
zipEntry.async('blob').then((blob) => {
const url = URL.createObjectURL(blob); // создаем "урл" для блоба
img.src = url; // ставим в картинку
setTimeout(() => {
URL.revokeObjectURL(url); // удаляем, чтобы не было утечек памяти
}, 100);
})
int Min(int arr[], int n, int current) {
return n > 0 ? Min(arr, n - 1, min(current, arr[n-1])) : current;
}
int minValue = Min(arr, n, +бесконечность)
int Min(int arr[], int n) {
return n > 0 ? min(Min(arr, n - 1), arr[n-1])) : +бесконечность;
}
int minValue = Min(arr, n);
Возможности перейти на функциональный компонент к сожалению нет.легаси-проект со старым реактом версии менее 16, "тронешь-развалится"?
import { useRef, useEffect, useState } from 'react';
export default function App() {
const [count, setCount] = useState(0);
const countRef = useRef();
countRef.current = count;
useEffect(() => {
const clickEvent = () => {
console.log(`CountRef: ${countRef.current}`);
};
document.addEventListener('click', clickEvent);
return () => {
document.removeEventListener('click', clickEvent);
};
}, [countRef]);
return (
<div>
<button onClick={() => setCount((n) => n + 1)}>Count: {count}</button>
</div>
);
}
useEffect(() => {
countRef.current = count;
}, [countRef, count]);