@mittwald/react-ghostmaker - npm explorer}>

Loading author...}>



);
}

function BlogTitle(props: { ghost: ReactGhost }) {
const { value: title, invalidate } = props.ghost
.getDetailed()
.title.transform((t) => t.charAt(0).toUpperCase() + t.slice(1))
.useGhost();

return (


{title}




);
}

function BlogAuthor(props: { ghost: ReactGhost }) {
const author = props.ghost.getDetailed().getAuthor().use();

return (


By: {author.name}


{author.bio}



);
}

// App.tsx
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ErrorBoundary } from "react-error-boundary";
import BlogPage from "./components/BlogPage";
import { BlogGhost } from "./models/react/BlogGhost";
import "./models/react/init"; // Initialize model identifiers

const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 5 60 1000, // 5 minutes
retry: 2,
},
},
});

function ErrorFallback({ error, resetErrorBoundary }: any) {
return (


Oops! Something went wrong


{error.message}




);
}

export default function App() {
const blogGhost = BlogGhost.ofId("123");

return (





);
}
`

πŸ” API Reference

$3

Creates a ghost proxy from any object or class instance.

Key Benefits:

- πŸ”‘ Automatic Query Keys: Generated based on method chains and model
identifiers
- πŸ”„ Smart Caching: Each method call in a chain creates a unique,
deterministic cache key
- 🎯 Type Safety: Preserves all original method signatures and return types

$3

- .use(options?) - Suspends until data is available, returns the resolved
value
-
.useGhost(options?) - Returns { value, invalidate } with full query
control
-
.render(transform?) - Renders the value directly as a React element
-
.transform(fn, deps?) - Transforms the resolved value
-
.invalidate(queryClient) - Invalidate this specific ghost's cached data
-
await ghost - Directly await the ghost to get the resolved value


$3

- asGhostProps(props) - Converts props to ghost-compatible format
-
GhostMakerModel(options) - Decorator to define model name and ID for automatic query key generation
-
invalidateGhostsById(id) - Globally invalidate cached data by ID
-
getGhostId(ghost) - Get the unique ID of a ghost

$3

- MaybeReactGhost - Type for props that accept both ghosts and regular objects
-
ReactGhost - Type for ghost proxy objects
-
UseGhostReturn - Return type of useGhost() with { value, invalidate }`

🀝 Requirements

- React >=19.2
- TanStack Query ^5
- TypeScript (recommended)

πŸ“„ License

MIT Β© Mittwald CM Service GmbH & Co. KG

---

Ready to make your async operations disappear like ghosts? πŸ‘» Transform your
React app with suspense-ready domain models today!