Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TS how can I this function write to a arrow function?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading