Answer the question
In order to leave comments, you need to log in
How to export from the App.js file not only the App component but also an array that is outside the App component?
I passed the App component to the index.js file:
import React from "react";
import ReactDOM from 'react-dom';
import App from "./App";
ReactDOM.render(<App attributeApp={carsArray} />, document.getElementById('root'));
import React from "react";
import ReactDOM from 'react-dom';
import {BrowserRouter, Route, Link, Switch} from "react-router-dom";
import createBrowserHistory from "history/createBrowserHistory";
import './App.css';
import Header from "./smallComponents/Header.js";
import Footer from "./smallComponents/Footer.js";
import Home from "./pageComponents/Home.js";
import About from "./pageComponents/About.js";
import Contacts from "./pageComponents/Contacts.js";
import CarsList from "./pageComponents/CarsList.js";
let carsArray = [
{
id:1,
name: 'BMW',
phone: '555 555 5555'
},
{
id:2,
name: 'Mercedes',
phone: '555 111 5555'
},
{
id:3,
name: 'Audi',
phone: '555 777 5555'
},
{
id:4,
name: 'Ford',
phone: '555 888 5555'
}
]
const history = createBrowserHistory();
class App extends React.Component {
render(){
return (
<BrowserRouter history={history}>
<div className="wrapper">
<Header/>
<CarsList attributeCarsList={this.props.attributeApp}/>
<Switch>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/contacts" component={Contacts} />
</Switch>
<Footer/>
</div>
</BrowserRouter>
)
}
}
export default App;
Answer the question
In order to leave comments, you need to log in
export let carsArray ...
import App, { carsArray } from "./App";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question