mirror of
https://github.com/penxio/penx.git
synced 2026-01-13 23:48:18 -05:00
24 lines
513 B
TypeScript
24 lines
513 B
TypeScript
import { store } from '@/store'
|
|
import { atom, useAtom } from 'jotai'
|
|
import { Post } from './usePost'
|
|
|
|
export const postsAtom = atom<Post[]>([])
|
|
|
|
export function usePosts() {
|
|
const [posts, setPosts] = useAtom(postsAtom)
|
|
return { posts, setPosts }
|
|
}
|
|
|
|
export function updatePostTitleById(id: string, title: string) {
|
|
const posts = store.get(postsAtom)
|
|
store.set(
|
|
postsAtom,
|
|
posts.map((post) => {
|
|
if (post.id === id) {
|
|
return { ...post, title }
|
|
}
|
|
return post
|
|
}),
|
|
)
|
|
}
|