In ReScript, how would you do what you would normally do with guard clauses in JS? For example:
function MyComponent() {
let result = loadSomeData();
if (!result) {
return "No data loaded";
}
// complex render based on the data
}
In ReScript I’m using a switch
but this causes a lot of nesting for the most important part of the function which reduces readability.
i.e.
@react.component
let make = () => {
let result = loadSomeData();
switch (result) {
| None => React.string("No data loaded")
| Some(data) => {
// complex render based on the data
}
}
}
The above is a somewhat simplified example, in the actual component where I’m facing this the data loading takes a state value as argument and the component rendered with data will change that state to change what it’s displaying.