[NextJs 14] Summarize data fetching architecture

Introduction

In this article, I am gonna summarize the modes about data fetching in NextJs for better understanding of NextJs.

API Router Mode

Tranditionally,we use fetch or axios tool to request data by HTTP-Request.

This mode, meanwhile, is supposed to offer api to outside world in public.

However, when you use fetch-api in Server Component,that obviously is inapproriate. Because why fecthing api in the same place. In Server Component, we can directly call the function service from server.

Server Component Call Service Mode

In Server Component, we can call the service function from server, at the same time,remain the api ability in public.

Client Component Call Service Mode

In Client Component, we can't call the service function from server directly. because, the service does not exist in Client Side. But, we can continue to use api router mode.

If we want to do this, we should mark service file as "use server"

相关推荐
5***79003 分钟前
Vue项目性能优化
前端·javascript·vue.js
丫丫72373411 分钟前
Three.js 模型树结构与节点查询学习笔记
javascript·webgl
车传新31 分钟前
Javascript
javascript
天若有情6731 小时前
【c++】手撸C++ Promise:从零实现通用异步回调组件,支持链式调用+异常安全
开发语言·前端·javascript·c++·promise
抱琴_1 小时前
【Vue3】大屏性能优化黑科技:Vue 3 中实现请求合并,让你的大屏飞起来!
前端·vue.js
不会玩电脑的Xin.1 小时前
HTML + CSS
前端·css·html
hadage2331 小时前
--- JavaScript 的一些常用语法总结 ---
java·前端·javascript
彭于晏爱编程1 小时前
🍭🍭🍭升级 AntD 6:做第一个吃螃蟹的人
前端
掘金一周2 小时前
大部分人都错了!这才是chrome插件多脚本通信的正确姿势 | 掘金一周 11.27
前端·人工智能·后端