3 ms·
You can just write an IIFE expression, and use regular imperative logic like if/else and switch statements. If you find the syntax ugly, you can create a funct
by gavinray 1y ago
You can just write an IIFE expression, and use regular imperative logic like if/else and switch statements.
If you find the syntax ugly, you can create a function like "run(expr)" to wrap it, similar to Kotlin's method of the same thing.
<div>
{(() => {
switch (status) {
case Status.LOADING: return <div className="loading">Loading...</div>
case Status.ERROR: return <div className="error">Error: {error.message}</div>
case Status.SUCCESS: return <MyComponent data={data} />
}
})()}
</div>