Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
Dictionary in react js

I'm creating an interactive viz with React and I would like to add a slider in my viz.

import "./styles.css";
import React from "react";
import Sunburst from "react-zoomable-sunburst";
import { data } from "./data";
import { Slider } from "@mui/material";

class App extends React.Component {
  onSelect(event) {
    console.log(event);

    const obj = {
      e: 2016,
      d: 2017,
      c: 2018,
      b: 2017,
      a: 2016
    };

    console.log("Object.entries");
    console.log(Object.entries(obj));
  }

  render() {
    return (
      <div className="App">
        <Sunburst
          width="400"
          height="400"
          data={data.a}
          count_member="size"
          labelFunc={(node) => node.data.name}
          _debug={false}
        />
        <Slider
          aria-label="Year"
          defaultValue={2016}
          valueLabelDisplay="auto"
          step={1}
          marks
          min={2016}
          max={2020}
        />
      </div>
    );
  }
}

export default App;

Above is my code. I added my data from 2016 to 2020 in data.js file and I want my viz to change according to the year as I move my slider.

  a: {
    name: "2016",
    children: [
      {
        name: "Campus",
        children: [
          {
            name: "Liabilities",
            children: [
              {
                name: "Current Liabilities",
                children: [
                  { name: "Accounts payable", size: 53010 },
                  { name: "Accrued salaries", size: 23554 },
                  { name: "Unearned revenue", size: 253322 },
                  { name: "Commercial paper", size: 326008 },
                  { name: "Current portion of long-term debt", size: 112431 },
                  { name: "Funds held for others", size: 2500 },
                  { name: "Other current liabilities", size: 71036 }
                ]
              }

This is a part of my code in data.js and I named 2016 data as a, 2017 as b, and so on. I wanted to name as 2016, 2017... instead of a,b... but this didn't work since data.2016 didn't work. (So I made it data.a in the code above). I tried data['2016'] instead of data.a but this came out with the error: /src/App.js: JSX value should be either an expression or a quoted JSX text (17:15).

So currently, my slider doesn't work. I created the dictionary in the code above but not sure what to do with the dictionary (I'm not that familiar to React js) Is there any way to use dictionary or other method in React to resolve this problem?

Thanks.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda