-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making defaultProps an asynchronous function that returns an object? #496
Comments
You could probably do something with resolveData and check if any data exists before deciding whether or not to call your API, but perhaps not ideal. Wonder if a |
yes, but I guess an async function that returns the desired object is enough for this. |
@chrisvxd I was wondering if this is in your priority list. Would be great to have in coming release. |
It's not on my radar right now, but should be easy to implement with the existing |
Closing in favour of #557 |
Hi @chrisvxd. Sorry to mention again. Regarding #557, i was thinking about the situation when you would want to give initial data to the component but using async requests. What i understand about resolveData is that it triggers everytime the data changes. I mean, it would be like i want to get 10 items for array type initially and let the user delete, add or edit according to his/her needs, but definitely don't want it to fetch 10 items again and again. My concept is to get the initial data from sources and let the user do anything he wants after inserting and dont go with the overhead of resolveData. I'm not very good with these things, but please correct me. Ps: Thanks for looking at this. |
@Roshan54321 I believe you could configure the resolveData API to only trigger once: const config = {
components: {
HeadingBlock: {
fields: {
title: {
type: "text",
},
},
resolveData: async ({ props }) => {
if (props.loaded) return;
return {
props: {
title: "Hello, world",
loaded: true
},
};
},
render: ({ title }) => {
return <h1>{title}</h1>;
},
},
},
}; |
Yes, tried doing like that except, it didn't work on first load. This now looks fixed. But still i feel bad using resolveData (which definitely was made for another purpose) to mix my initialFetching logic. Thanks for looking into it! |
@Roshan54321 that's a fair concern. I generally prefer explicit APIs, too, but in this case worry about the amount of complex logic that underpins For the time-being, I don't think there's anything hugely wrong with using |
I don't exactly know how I should populate the fields at first render (from external api). I don't want to call an api everytime the appState changes, rather call the api in defaultProps.
Is there a better way that exists?
The text was updated successfully, but these errors were encountered: