Guest User

Untitled

a guest
Aug 19th, 2019
69
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const [name, setName] = useState('');
  2. const [miss, setMiss] = useState('');
  3. async function saveDisciplina() {
  4. const realm = await getRealm();
  5. const disciplinaRealm = realm.objects('Disciplina').sorted('id', true);
  6. const lastIdInserted = disciplinaRealm.slice(0, 1)[0].id;
  7. const data = {
  8. id: lastIdInserted ? parseInt(lastIdInserted + 1) : 1,
  9. name: name,
  10. maximum_miss: miss,
  11. miss_quantity: '0',
  12. };
  13.  
  14. realm.write(() => {
  15. realm.create('Disciplina', data);
  16. });
  17. navigation.navigate('Home');
  18. }
  19.  
  20. const [disciplinas, setdisciplinas] = useState([]);
  21. useEffect(() => {
  22. async function getDisciplinas() {
  23. const realm = await getRealm();
  24. const data = realm.objects('Disciplina').sorted('name');
  25. if (data.length) setdisciplinas(data);
  26. }
  27. getDisciplinas();
  28. }, []);
  29.  
  30. <Flatlist
  31. keyboardShouldPersistTaps="handled"
  32. data={disciplinas}
  33. keyExtractor={item => String(item.id)}
  34. renderItem={({item}) => <Disciplinas data={item} />}
  35. />
RAW Paste Data