Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/crutchcorn/react-native-monorepo-example. An example of a Yarn Berry monorepo with workspace and Re
Something went wrong. Try again.
123456789101112131415161718192021222324import AsyncStorage from "@react-native-async-storage/async-storage";import { UserMessage } from "../types/message";import { v4 as uuidv4 } from "uuid";
const messagesKey = "MESSAGES";
export const loadMessages = async () => { const data = await AsyncStorage.getItem(messagesKey); if (!data) return []; return JSON.parse(data) as UserMessage[];};
export const addMessage = async (message: Omit<UserMessage, "id">) => { const messages = await loadMessages(); const newMessages = [ ...messages, { ...message, id: uuidv4(), }, ]; await AsyncStorage.setItem(messagesKey, JSON.stringify(newMessages));};