
๐ ์ํฉ
ํ๊ฒฝ) @react-navigation/native - goBack() ์ฌ์ฉ, realm.delete() ์ฌ์ฉ
A ํ๋ฉด: ๋ฐ์ดํฐ ๋ชฉ๋ก์ ๋ณด์ฌ์ค.
B ํ๋ฉด: ๊ฐ ๋ฐ์ดํฐ ์์ธ ๋ด์ฉ์ ๋ณด์ฌ์ค.
Aํ๋ฉด์์ ๋ฐ์ดํฐ ์ ํ ํ Bํ๋ฉด ์ง์ . Bํ๋ฉด์์ ํด๋น ๋ฐ์ดํฐ ์ญ์ ๋ฒํผ์ ๋๋ฅด๋ฉด Aํ๋ฉด์ผ๋ก ๋์๊ฐ.
์ด ๋, Accessing object which has been invalidated or deleted ์๋ฌ ๋ฐ์.
๐ ์์ธ
Realm ๊ฐ์ฒด๋ฅผ ์ญ์ ํ ํ์๋ ์ฑ์์ ํด๋น ๊ฐ์ฒด๋ฅผ ์ฐธ์กฐ.
๐ก ํด๊ฒฐ ๋ฐฉ๋ฒ
Realm ๊ฐ์ฒด๋ฅผ ์ญ์ ํ ํ์๋ ์ฑ์์ ํด๋น ๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ์ง ๋ชปํ๋๋ก ํด์ผํจ.
Object.assign({}, realmObject)๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ์ฒด๋ฅผ ๋ณต์ฌํ๊ณ ๋ฆฌ์คํธ์ ๋ณต์ฌ๋ ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ๋๋ก ํจ.
const realm = useRealm();
const notes = realm.objects('Note');
// ์์ ์
const noteList = Array.from(notes);
setNoteList(noteList);
// ์์ ํ
const noteList = Array.from(notes);
const copiedNotes = noteList.map((note) => Object.assign({}, note));
setNoteList(copiedNotes);
