next superjson plugin
v0.6.1
export default function Page ( { date } ) {
return < div > Today is { date . toDateString ( ) } </ div > ;
}
// You can also use getInitialProps, getStaticProps
export const getServerSideProps = ( ) => {
return {
props : {
date : new Date ( ) ,
} ,
} ;
} ; // Use "data-superjson" attribute to pass non-serializable props to client components
// No needs to change the propsType of Client Component (It's type-safe!)
export default function ServerComponent ( ) {
const date = new Date ( ) ;
return < ClientComponent date = { date } data-superjson /> ;
}data-superjson для компонента сервера> сериализация клиентских компонентов. Сначала установите пакеты:
npm install superjson next-superjson-plugin
# or Yarn
yarn add superjson next-superjson-plugin Добавить плагин в next.config.js
// next.config.js
module . exports = {
experimental : {
swcPlugins : [ [ "next-superjson-plugin" , { } ] ] ,
} ,
} ; Вы можете использовать excluded опцию, чтобы исключить конкретные свойства из сериализации.
[ 'next-superjson-plugin' , { excluded : [ "someProp" ] } ] , секвенированная
Участник Next.js
Участник плагин SWC
Участник Суперджсон
Next.js->> плагин SWC: преобразование запроса
Плагин SWC->> плагин SWC: преобразование страниц/компонентов <br> для использования Superjson
Плагин SWC->> next.js: Take Modules
Next.js-> Superjson: Connected
Next.js->> Superjson: Serialize Reps <br> (дата, биглинт, установка, карта ..)
Примечание к плагину SWC: GetInitialProps <br> GetserverSideProps <br> GetStaticProps <br> Компоненты сервера
Superjson->> Next.js: Deserialize Reps
Примечание к плагину SWC: страницы <br> Клиентские компоненты
Плагин всегда обеспечивает совместимость только с версией Canary Next.js.
Оставить проблему