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

219
Views
Trying to style data rendered from my DB with styled components and getting Invalid hook call error

So I'm trying to style data from my rendered react components and have the following Issue.

I think my issue is "Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:" but I'm unable to fix this.

import {useEffect, useState} from "react";
import React from 'react'
import styled from 'styled-components';
import ButtonUnstyled from '@mui/base/ButtonUnstyled';
// import { Title } from '../MainElements';
const API_BASE = "http://localhost:3001";


export const RocketCard = () => {
  const [rockets, setRockets] = useState([{
    name: '',
    id: ''
  }])

  useEffect(() => {
      fetch(API_BASE + '/rockets')
        .then(res => res.json())
        .then(data => setRockets(data))
        .catch((err) => console.error("Error: ", err));
    },[])


  return ( <div className="container">
  
    <Title>Test</Title>
    {rockets.map(rocket =>
    <div className="rocket" key={rocket._id} >
      <h1>{rocket.name}</h1>
    </div>
    )}
  </div>
);

}

const Title = styled.h1`
display: flex;
align-items: center;
line-height: 1.2;
`;

Console Errors

about 4 years ago · Juan Pablo Isaza
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!