Hi Pablo !
Thanks for the inspiration and the detailed article.
To me the biggest shortcoming of this implementation is that you do not control when the data is fetched (on your github repo, it is always done on created).
To circumvent this i thought about using a Promise as a prop instead of the apiMethods params and updater (this also makes the component simpler and much more flexible)
Then changing the promise props acts as a reload (or could eventually load something different, it is up to the user). The promise prop can also be omitted if the fetching has to occur later than the component creation (in response to a user action for example)
Hey @gmeral
thanks for commenting. You are right, in the current implementation, the request will be executed each time the component is created.
Your suggestion is pretty good.
The only thing I'd do there is changing the promises callbacks to async/await
In my personal projects, I've done something similar to your implementation.
But I pass a boolean intermediate prop combined with a params watcher.
Like this:
The difference is that this doesn't allow me to make different requests but the same one with different parameters.
I kind of don't see with good eyes scenarios where you might populate the same variable and context with different requests results, but it might happen.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Pablo !
Thanks for the inspiration and the detailed article.
To me the biggest shortcoming of this implementation is that you do not control when the data is fetched (on your github repo, it is always done on created).
To circumvent this i thought about using a Promise as a prop instead of the apiMethods params and updater (this also makes the component simpler and much more flexible)
Then changing the promise props acts as a reload (or could eventually load something different, it is up to the user). The promise prop can also be omitted if the fetching has to occur later than the component creation (in response to a user action for example)
Here is how it would look like :
Hey @gmeral thanks for commenting. You are right, in the current implementation, the request will be executed each time the component is created.
Your suggestion is pretty good.
The only thing I'd do there is changing the promises callbacks to async/await
In my personal projects, I've done something similar to your implementation.
But I pass a boolean intermediate prop combined with a params watcher.
Like this:
The difference is that this doesn't allow me to make different requests but the same one with different parameters.
I kind of don't see with good eyes scenarios where you might populate the same variable and context with different requests results, but it might happen.