MCPcopy Create free account
hub / github.com/TanStack/devtools / Post

Function Post

examples/preact/basic/src/index.tsx:65–112  ·  view source on GitHub ↗
({
  postId,
  setPostId,
}: {
  postId: number
  setPostId: (id: number) => void
})

Source from the content-addressed store, hash-verified

63}
64
65function Post({
66 postId,
67 setPostId,
68}: {
69 postId: number
70 setPostId: (id: number) => void
71}) {
72 const [post, setPost] = useState<Post | null>(null)
73 const [loading, setLoading] = useState(true)
74 const [error, setError] = useState<Error | null>(null)
75
76 useEffect(() => {
77 if (postId > 0) {
78 setLoading(true)
79 getPostById(postId)
80 .then((data) => {
81 setPost(data)
82 setLoading(false)
83 })
84 .catch((err) => {
85 setError(err)
86 setLoading(false)
87 })
88 }
89 }, [postId])
90
91 return (
92 <div>
93 <div>
94 <a onClick={() => setPostId(-1)} href="#">
95 Back
96 </a>
97 </div>
98 {!postId || loading ? (
99 'Loading...'
100 ) : error ? (
101 <span>Error: {error.message}</span>
102 ) : post ? (
103 <>
104 <h1>{post.title}</h1>
105 <div>
106 <p>{post.body}</p>
107 </div>
108 </>
109 ) : null}
110 </div>
111 )
112}
113
114const Context = createContext<{
115 count: number

Callers

nothing calls this directly

Calls 1

getPostByIdFunction · 0.70

Tested by

no test coverage detected