Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
next js - cómo crear hoc para la página

Cuando uso el siguiente código, tengo el error

 Error: The default export is not a React Component in page: "/"

páginas/index.tsx

 import React, { useState, useRef } from "react"; import type { NextPage } from "next"; import WithToast from "hoc/WithToast/WithToast"; const Home: NextPage = () => { return ( <div> Home </div> ); }; export default WithToast(Home);

ConToast.tsx

 import React from "react"; import { ToastContainer, Zoom } from "react-toastify"; import { NextComponentType, NextPageContext } from "next"; function WithToast(Component: NextComponentType<NextPageContext, any, {}>) { return ( <div className="with-toast"> <ToastContainer transition={Zoom} position="top-center" autoClose={200} hideProgressBar={true} draggable={false} closeButton={false} /> {Component} </div> ); } export default WithToast;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Deberías llamar al Component envuelto así:

 function withToast(Component: NextComponentType<NextPageContext, any, {}>) { return ( <div className="with-toast"> <ToastContainer transition={Zoom} position="top-center" autoClose={200} hideProgressBar={true} draggable={false} closeButton={false} /> <Component /> </div> ); }

o así:

 function withToast(component: NextComponentType<NextPageContext, any, {}>) { return ( <div className="with-toast"> <ToastContainer transition={Zoom} position="top-center" autoClose={200} hideProgressBar={true} draggable={false} closeButton={false} /> {component()} </div> ); }

O básicamente está tratando de representar un objeto de función en JSX como un niño, y eso genera una excepción. Los nombres HOC no deben comenzar con un carácter en mayúsculas.

Ese error de NextJS solo debería deberse al hecho de que tuvo ese error que no se detectó durante el procesamiento de SS.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!