0

I'm newby in React JS and I trying to integrate the component https://github.com/AndrewRedican/react-json-editor-ajrm/ in my App without using JSX.

The project not use import syntax like import Component from library but use the the syntax like const Component = require(library)`.

There is the snippet where the component is integrated:

  makeMessageElement() {
    const textFieldOptions = {
      width: '100%',
      placeholder: 'Enter message',
      value: this.state.message,
      onChange: (event, value) => {
        this.setState({
          message: value
        })
      }
    }
 
    return React.createElement(JSONInput, textFieldOptions, null)
  }

When I trying const JSONInput = require('react-json-editor-ajrm'), I get the message :

Uncaught Invariant Violation: 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, or you might have mixed up default and named imports.

When I trying const {JSONInput} = require('react-json-editor-ajrm'), I get the same message.

When I trying import JSONInput from "react-json-editor-ajrm";, I get the message :

Uncaught Component.js:8
import JSONInput from "react-json-editor-ajrm";
SyntaxError: Unexpected identifier

So, what is the right way to import the library please ?

2
  • what about import {JSONInput} from 'react-json-editor-ajrm' Commented Dec 7, 2020 at 14:36
  • I get the same message than import JSONInput from "react-json-editor-ajrm"; Commented Dec 7, 2020 at 14:58

2 Answers 2

1

Just try the require(path).default:

const JSONInput = require('react-json-editor-ajrm').default

and for more details

Sign up to request clarification or add additional context in comments.

Comments

1

Did you try this :

import * as JSONInput from "react-json-editor-ajrm";

or

import { JSONInput } from "react-json-editor-ajrm";

If it doesn't work, just tell me and we'll look more into this together :)

Edit for the require :

const JSONInput = require('react-json-editor-ajrm').default

2 Comments

I have the following message: import * as JSONInput from "react-json-editor-ajrm"; SyntaxError: Unexpected token *. I think that the project is not configured to use syntax import .... (e.g. Webpack). But I would'nt reconfigure the project just to import this comporent and use component. If there is another way...
Oh sry, did not see your answer. Try this maybe : const JSONInput = require('react-json-editor-ajrm').default

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.