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

159
Views
Type script type from prev

I'm not sure which type to designate here.

"HowitterObject" in setHowitters is data and "...prev' is the continuous addition of data from howitterObject.

 interface IhowitterMessage {
  message: string;
  createAt: number;
  id: string;
}

const Home = () => {
const [howitters, setHowitters] = useState<IhowitterMessage[]>([]);

  const getHowitters = async () => {
    const dbHowitter = await dbService.collection("howitter").get();
    dbHowitter.forEach((document) => {
      const howitterObject = {
        ...document.data(),
        id: document.id,
      };
      setHowitters((prev: ???) => [howitterObject, ...prev]); //What should I put in the "prev" type?
    });
  };

  useEffect(() => {
    getHowitters();
  }, []);

  return(
    <div>
       {howitters.map((howitter: IhowitterMessage) => (
          <div key={howitter.id}>
            <h4>{howitter.message}</h4>
          </div>
        ))}
    </div>
   );
};

If you console.log(howitters), it is as follows.

(3) [{...}, {...}, {...}]
    0: {message: "no", createAt: 1631367025550, id: "q2d9TTgh36mgFZwMQ5EA"}
    1: {createAt: 1631365463319, message: "Good", id: "nCABFp1v3dP73gIbckpp"}
    2: {message: "hey", createAt: 1631367021665, id: "dmNBa6C8NwhDQDYDOP36"}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It's similar to your state's type

Because prev is your previous state of howitters so you could put IhowitterMessage[] there too:

setHowitters((prev: IhowitterMessage[]) =>
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!