0
Good morning, I’m developing a component with React, but I’m not able to assign values from a file I created for default information. Example:
created this menu-items.js file
`export default {
items:[
{
id: 1,
title:'NFC-e',
icon:'fa fa-file',
url:'',
},
{
id: 2,
title:'NF-e',
icon:'fa fa-file',
url:'',
},
]
}`
and would like to read this information in my component index.js file, to render the component already with the attributes.
What I’ve done so far.
import React, { useState, useEffect } from 'react';
import items from './menu-item';
import './styles.css';
export default function Sidebar() {
const [repositores, setRespositories] = useState([]);
useEffect(() => {
setRespositories(items);
}, []);
return (
<div className="main-sidebar">
<div className="container-sidebar">
<ul>
{items.map((repo, index) => (
<li key={index}>{repo.title}</li>
))}
</ul>
</div>
</div>
);
}
Good afternoon Matheus Gomes, I tried this way, but it generates the error that the map is not a function, I was able to assign a name to the import this way. import data from './menu-items'; data.items.map(item => ( <li key={index}>{Repo.title}</li> ))
– Projetos React