filestack / filestack-react

Official React component for Filestack - API and content management system that makes it easy to add powerful file uploading and transformation capabilities to any web or mobile application.
https://www.filestack.com
MIT License
164 stars 40 forks source link

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. #83

Closed Vadorequest closed 4 years ago

Vadorequest commented 4 years ago

I'm trying to get started with this lib and got stuck right away.

/** @jsx jsx */
import { jsx } from '@emotion/core';
import React from 'react';

import { Record } from '../../../utils/record';

const AssetInput = (props: Props) => {
  const {
    label,
    source,
    record,
  } = props;
  const FileStackAssetPicker = require('filestack-react');
  console.debug('AssetInput.props', props);
  console.debug('FileStackAssetPicker', FileStackAssetPicker);

  return (
    <div>
      {label}
      <FileStackAssetPicker
        apikey={'TOKEN'}
      />
    </div>
  );
};

type Props = {
  source: string;
  record?: Record;
  label?: string;
}

export default AssetInput;

This renders: image

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

Vadorequest commented 4 years ago

Found solution when writing issue, by looking at the content of FileStackAssetPicker.

Because I'm loading using require and not import (because the lib doesn't support SSR), I had to import it using:

  const FileStackAssetPicker = require('filestack-react').default;

The .default changes everything :)