Skip to content

Instantly share code, notes, and snippets.

@vinipachecov
Last active May 30, 2020 22:20
Show Gist options
  • Save vinipachecov/755db6f5f27ce1b54c0f769d23f2583a to your computer and use it in GitHub Desktop.
Save vinipachecov/755db6f5f27ce1b54c0f769d23f2583a to your computer and use it in GitHub Desktop.
getAuthors callback from App.tsx in React-Native TypeORM setup
const getAuthors = useCallback(async () => {
const authorRepository = getRepository(Author);
let result = await authorRepository.find();
if (result.length === 0) {
const newAuthor = new Author();
newAuthor.birthdate = '10–03–1940';
newAuthor.name = 'Chuck Norris';
await authorRepository.save(newAuthor);
result = await authorRepository.find();
}
setAuthors(result);
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment