Core Concepts
Understanding the core concepts behind Minimact will help you build better applications.
Server-Side React
Minimact brings the React development experience to the server. You write familiar JSX/TSX components, but they run entirely on the ASP.NET Core server.
How It Works
- Write JSX/TSX - Use familiar React syntax
- Transpile to C# - Babel converts your components to C# classes
- Server Rendering - Components render HTML on the server
- SignalR Communication - Real-time updates via SignalR
- DOM Patching - Efficient client-side DOM updates
State Management
Server State
Server state is managed by your C# component and lives on the server:
const [count, setCount] = useState(0); // Lives on serverThis transpiles to:
private int count = 0;
public void SetCount(int value)
{
count = value;
StateHasChanged();
}Component Lifecycle
Minimact components follow a simplified lifecycle:
- Mount - Component is created on the server
- Render - HTML is generated and sent to client
- Update - State changes trigger re-renders
- Unmount - Component is disposed
export function MyComponent() {
useEffect(() => {
console.log('Component mounted');
return () => {
console.log('Component unmounted');
};
}, []);
return <div>Hello</div>;
}Hooks
Minimact provides a comprehensive set of hooks:
Core React Hooks:
- ✅
useState- Reactive state management - ✅
useEffect- Lifecycle and side effects - ✅
useRef- Mutable references - ✅
useContext/createContext- Context API - ✅
useComputed- Computed/derived values
Server-Side Hooks:
- 🆕
useServerTask- Long-running async operations - 🆕
usePaginatedServerTask- Paginated data loading - 🆕
useServerReducer- Complex state patterns
Utility Hooks:
- 🆕
usePub/useSub- Pub/sub messaging - 🆕
useMicroTask/useMacroTask- Task scheduling - 🆕
useAnimationFrame/useIdleCallback- Timing control - 🆕
useSignalR- Custom SignalR hub connections - 🆕
useMarkdown- Server-side markdown rendering
Event Handlers
Event handlers are automatically wired to call server methods:
<button onClick={() => setCount(count + 1)}>
Increment
</button>This becomes:
<button onclick="increment">Increment</button>
[ServerMethod]
public void Increment()
{
count++;
StateHasChanged();
}Predictive Updates
Minimact's killer feature: it predicts what will happen when you click a button and pre-sends the patches.
When the server detects a pattern (like incrementing a counter), it:
- Predicts the next state
- Generates DOM patches
- Sends them to the client before you click
- Client caches the patches
- You click → instant update (0ms latency)
- Server verifies and corrects if needed
Learn more in Predictive Rendering.
Next Steps
- Dive into Predictive Rendering
- Explore the API Reference
- See Examples
