In ReactJS, one can create a variable and include a map function by first declaring the variable and then using the map function within the component. If you

Having trouble integrating the accordian.js page into the app.js main page for compilation. Need help defining and writing out the function correctly, any suggestions?

Below is my code:

App.js: How do I incorporate the components from the accordian.js page into this app.js file?

import React from 'react'
import Typography from '@material-ui/core/Typography'
import Tabs from './Components/Tabs'
import Accordian from './Components/Accordian'

const data = {
  categories: [
    {
      name: 'Faces',
      subCategories: [{ name: 'Yellow', symbols: ['X', 'O', 'P'] }],
    },
    {
      name: 'Flags',
      subCategories: [
        { name: 'Popular', symbols: ['X', 'O', 'P'] },
        { name: 'Unknown', symbols: ['L', 'Z', 'Q'] },
      ],
    },
    {
      name: 'Numbers',
      subCategories: [
        { name: 'Big', symbols: ['X', 'O', 'P'] },
        { name: 'Small', symbols: ['L', 'Z', 'Q'] },
        { name: 'Random', symbols: ['R', 'T', 'M'] },
      ],
    },
  ],
}

const App = () => {
  const [tabIndex, setTabIndex] = React.useState(0)
  const handleTabChange = (event, newTabIndex) => {
    setTabIndex(newTabIndex)
  }
  return (
    <>
      <Accordian heading={subCat.name}>
        {subCat.symbols.map((symbol) => (
          <div>{symbol}</div>
        ))}
      </Accordian>
      <div className="App">
        <header className="App-header">Something</header>
        <Typography variant="h3">Placeholder_Symbols</Typography>
        <Tabs
          tab={tabIndex}
          tabs={data.categories}
          handleChange={handleTabChange}
        />
        <Accordian 
        heading={subCat.name}
        children={subCat.symbols}
         />
      </div>
    </>
  )
}

export default App

Accordian.js: Implemented a map function for app.js, unsure about how to define 'subCat' and if it's done correctly - encountering errors.

import React from 'react'
import { makeStyles } from '@material-ui/core/styles'
import ExpansionPanel from '@material-ui/core/ExpansionPanel'
import ExpansionPanelSummary from '@material-ui/core/ExpansionPanelSummary'
import ExpansionPanelDetails from '@material-ui/core/ExpansionPanelDetails'
import Typography from '@material-ui/core/Typography'
import ExpandMoreIcon from '@material-ui/icons/ExpandMore'

const useStyles = makeStyles((theme) => ({
  root: {
    width: '100%',
  },
  heading: {
    fontSize: theme.typography.pxToRem(15),
    fontWeight: theme.typography.fontWeightRegular,
  },
}))

export default function SimpleExpansionPanel({ heading, children }) {
  const classes = useStyles()

  return (
    <div className={classes.root}>
      <ExpansionPanel>
        <ExpansionPanelSummary
          expandIcon={<ExpandMoreIcon />}
          aria-controls="panel1a-content"
          id="panel1a-header"
        >
          <Typography className={classes.heading}>{heading}</Typography>
        </ExpansionPanelSummary>
        <ExpansionPanelDetails>{children}</ExpansionPanelDetails>
      </ExpansionPanel>
    </div>
  )
}

Answer №1

There doesn't appear to be a variable named subCat in scope. Can you clarify its origin? Is it meant to be connected to the data object mentioned earlier?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to call a hook outside of a function component's body results in an invalid hook call. The proper usage for hooks like useQuery is within the body

I am encountering an issue with my react project that involves apollo-graphql. The error message states: Invalid hook call. Hooks can only be called inside of the body of a function component Below is the snippet of code triggering this error: import Re ...

Determine the number of rows in an Ajax-fed datatable (including paginated rows) that have a specific value in a

I am struggling with counting rows in #datatableOne where the 'Status' column has a value of 'Unknown'. I have attempted a couple of solutions, but they are not giving me the desired results. The first solution only counts the rows on ...

Ensure that the sidebar automatically scrolls to the bottom once the main content has reached the bottom

I am facing an issue with a sticky sidebar that has a fixed height of calc(100vh-90px) and the main content. The sidebar contains dynamic content, which may exceed its defined height, resulting in a scrollbar. On the other hand, the main content is lengthy ...

Error: Attempting to access an undefined property ('call') on Next.js is causing a TypeError

Exploring the realms of Next.js and Typescript for a new project! My goal is to utilize next.js with typescript and tailwind CSS by simply entering this command: npx create-next-app -e with-tailwindcss my-project Smooth sailing until I hit a snag trying t ...

Refresh the div by clicking it

$(window).load(function() { $("#Button").click(function() { alert('clicked') $("#div").load(" #div > *"); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <script ...

What could be causing the error message "Error: Cannot modify headers after they are sent" to appear?

I am attempting to insert data into an MS SQL server when a JSON Data API POST request is made. var express = require('express'); var app = express(); var sql = require('mssql'); // Connection string parameters. var sqlConfig = { u ...

Guide to sending API requests from a React client to an Express server hosted on Heroku

I've been grappling with deploying a Twitch-like application using a combination of react, redux, node media server, and json server module to Heroku. One roadblock I keep hitting is when attempting to establish a connection between my react client an ...

In order to manage this file type properly, you might require a suitable loader, such as an arrow function within a React

Currently, I am in the process of creating an npm package and have encountered a difficulty with the following code: You may need an appropriate loader to handle this file type. | } | | holenNummerInSchnur = Schnur => { | if (this.beurte ...

Using Visual Studio Code, I am eager to upload a new version to GitHub via React

I've successfully created a Github repository and managed to push updates in the past, but I still lack confidence in my abilities. Could someone provide guidance on how to commit a new update to GitHub using Vscode's terminal? ...

Learn how to deactivate the pause button with just one click and re-enable it once the popup appears using Angular2 and Typescript

Can anyone assist with solving an issue I am facing with a timer and a pause button? I need the pause button to be disabled once clicked, until a popup appears, then it should become enabled again. My code snippet is provided below: HTML: <button md-i ...

Using Jquery to swap out div elements and reinitialize code after selecting a menu <a href>link<</a>

I have a jQuery script that swaps out a div when a href="#1" is clicked. The same link, a href="#1", is then replaced by a href="#2" and vice versa. Here is the jQuery code: $('.child2, a[href="#1"]').hide() $('#replacepagelinks a').c ...

Issue with autoplay slideshow functionality not activating when opened in a new tab

The owl.carousel.js plugin is used for creating a jQuery slideshow. Initially, the slideshow works correctly, but I noticed that the autoplay feature stops working when I open a new tab in Firefox or Chrome. Demo : Demo : $(document).ready(function () ...

Even after shutting down my PeerConnection, the black screen persists. I would appreciate assistance in resolving this issue

Welcome to the Room.js Client Side Code! import React, { useEffect, useRef, useState } from "react"; import io from "socket.io-client"; import Peer from "simple-peer"; import styled from "styled-components"; const C ...

Are MobX Observables interconnected with RxJS ones in any way?

Is the usage of RxJs observables in Angular comparable to that in React and MobX? I'm struggling to find information on this topic. ...

Deciding Between Javascript DOM and Canvas for Mobile Game Development

My idea for a mobile game involves using the Phonegap framework to create a game where players can control a ball's movement by utilizing their phone's accelerometer. I also envision incorporating other elements like enemies and walls into the ga ...

What is the best way to merge two JSON arrays using Axios in a React project?

I am currently working on getting data using axios React from Laravel, but I am facing some challenges in combining two arrays by their respective Ids. In my case, I am trying to retrieve product data and images from the Laravel Controller. Can anyone prov ...

Exploring the possibilities of custom layouts for specific routes within the pages directory in Next.js

I am interested in incorporating layout-based routing within my project's pages directory. I want to find a way to have a specific file, like the _app.tsx, that can only affect the files located inside a particular folder. This setup would operate si ...

The .NET controller does not receive traffic for the GET method

Having some trouble populating a table with JSON data using angular ng-repeat. No errors are showing up in the console, and my breakpoint in the .NET Controller isn't being triggered. Here's the code for the App Controller: var app = angular.mo ...

Having trouble sending form data using the jQuery AJAX POST method?

I am facing an issue with a simple form that is supposed to send data to PHP via AJAX. However, when I submit the form, the data does not get sent across. Here is the JavaScript code: $(document).ready(function(e) { $('#update').submit(func ...

Ways to add a substantial quantity of HTML to the DOM without relying on AJAX or excessive strings

Currently, I am looking to update a div with a large amount of HTML content when a button on my webpage is clicked. The approach I am currently using involves the .html() method in JQuery, passing in this extensive string: '<div class="container-f ...