user17220558
user17220558

Reputation: 1

How can export from default-exporting module in reacjs

How do I resolve this error, Should not import the named export 'destinations' (imported as 'destinations') from default-exporting module (only default export is available soon) Here the code snippet

import React from 'react'


import { useState } from 'react'


import {destinations} from '../assets/space-tourism-website-main/starter-code/data.json'


const Destinations = () => {

    const [planets] = useState(destinations)

    console.log(planets)

  return (

    <div>

    </div>
  )
}

export default Destinations

Upvotes: 0

Views: 120

Answers (1)

TheWhiteFang
TheWhiteFang

Reputation: 783

You cannot destructure a .json file, at least not with your current config. What you need to do is import the entire JSON and use the properties as is. Like so

import React from 'react'

import { useState } from 'react'


import dataJson from '../assets/space-tourism-website-main/starter-code/data.json'


const Destinations = () => {

    const [planets] = useState(dataJson.destinations)

    console.log(planets)

  return (

    <div>

    </div>
  )
}

export default Destinations

Upvotes: 1

Related Questions