Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

javascript - Spread Operator not working within Imported Modules. Works in my own code however

I'm using React 17.0.1 via CRA.

I have one module that I'm using called 'react-vimjs' that is causing this error. In node_modules/react-vimjs/src/main.tsx it uses the spread operator {...props} somewhere and this throws the error:

TypeError: React.__spread is not a function

However, when I use the spread operator in my OWN files (src/index.tsx), it works fine. But when I import that module & use it, it crashes. Why is this being interpreted differently? How do I fix this?

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import Vim, {FileUpload} from 'react-vimjs'
import reportWebVitals from './reportWebVitals';

class VimMarkdown extends React.Component<Props> {

  constructor(props: Props){
    super(props);
  }
  
  render = () => {
    const props = {
      memPath: './static/vim.js.mem',
    }
    return(
      <div className="vim">
        <Vim {...props} ref="vim"></Vim>
      </div>
    )
  }
}

interface Props{}

ReactDOM.render(
  <React.StrictMode>
  <VimMarkdown/>
  </React.StrictMode>,
  document.getElementById('root')
);
reportWebVitals();
question from:https://stackoverflow.com/questions/65912251/spread-operator-not-working-within-imported-modules-works-in-my-own-code-howeve

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...