Passing arguments to init
kofifus opened this issue · 4 comments
In the second example here
https://github.com/jorgebucaran/hyperapp/blob/main/docs/api/app.md#init
app({
// ...
init: (problems = 99) => [
{ loading: true },
butASPAAintOne(problems)
],
})
I am not clear how would one pass an argument (problems
) to Init ? I cannot find anything in the docs
If there is no way to pass a different problems
to the default wouldn't it be better to do:
app({
// ...
init: [
{ problems: 99, loading: true },
butASPAAintOne(problems)
],
})
Also on the same page it says init is required 100% but later says "Note that if you leave init: undefined the state will be set to an empty object ({}) by default" so I think one of these is wrong ?
?
Yes this is certainly an error. It still works because init behaves like an action but the state will be undefined. So problems will be set to 99, for use in the effect. But there is no reason why an example in the docs should be so confusing
You can't pass arguments to Hyperapp's init function. That's simply a way to create a variable with a default value without const/let. It should be noted, though.
OK I hope the docs can be amended there
If you see closely, your suggestion is actually a runtime error.