Nuxt-like asyncData
egoist opened this issue · 0 comments
egoist commented
Feature request
What problem does this feature solve?
Provide an alternative to Gatsby's page query and Nuxt's asyncData.
What does the proposed API look like?
export default {
async getInitialData({ getServerCache }) {
// On server-side, you can access Saber's Node API
if (process.server) {
const reposCount = await axios.get(`https://my.repos.count/api`)
// Return the data you want to inject as component data
// We cache the result as JSON so that you can access it via `getServerCache`
return { reposCount }
}
// On client-side, you use the server cache which is `{ reposCount }`
return getServerCache()
}
}