How can I write this generic function with a arrow function ?
function simpleState<T>(initial: T): [() => T, (v: T) => void] {
let value: T = initial;
return [
() => value,
(v: T) => {
value = v;
}
]
};
>Solution :
const simpleState = <T>(initial: T): [() => T, (v: T) => void] => {
// same function body as before
}
Since you tagged react-native, be aware that in a .tsx file, this will probably not work, since the <T> will be parsed as being a JSX tag, but you can do it in a .ts file, then import it into a .tsx file.