Component exporting error in reactjs

124 Views Asked by At

I'm trying to use the following react library to create a rich url preview component for my application.

https://docs.microlink.io/sdk/getting-started/react/

In the above documentation there's a working demo, so there's no question about the library. But when i try to use this library i'm getting the following error.

Uncaught (in promise) Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.

My code

import MicrolinkCard from 'react-microlink'

class Star extends Component {
  render() {
    <MicrolinkCard url='https://www.theverge.com/tldr/2018/2/7/16984284/tesla-space-falcon-heavy-launch-elon-musk'/>
  }
}

I tried changing import MicrolinkCard from 'react-microlink' to import {MicrolinkCard} from 'react-microlink' but still get the same error.

2

There are 2 best solutions below

1
On

you need to return it in your render:

 class Star extends Component {

   render() {

      return <MicrolinkCard url='https://blah.potato'/>

   }

}
0
On
import {MicrolinkCard} from 'react-microlink'

Please check the import thing as well.

 class Star extends Component {

   render() {

      return <MicrolinkCard url='https://google.com'/>

   }

}