简体   繁体   English

导入样式组件中的错误到组件React

[英]error in import styled-components to components React

I imported styled-components to component. 我将styled-components导入组件。
import styled, { keyframes } from 'styled-components';
the error TypeError: Object(...) is not a function var ThemeContext = createContext(); 错误TypeError: Object(...) is not a function var ThemeContext = createContext(); occurred. 发生了。

my package.js 我的package.js

"dependencies": {
    "prop-types": "^15.6.0",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-redux": "^5.0.6",
    "react-scripts": "1.1.0",
    "redux": "^3.7.2",
    "styled-components": "^4.2.0"
  },

code of component 组件代码

import React from 'react';
import PropTypes from 'prop-types';
import styled, { keyframes } from 'styled-components';
import FlyingObjectBase from './FlyingObjectBase';
import FlyingObjectTop from './FlyingObjectTop';

const FlyingObject = props => (
    <g>
      <FlyingObjectBase position={props.position} />
      <FlyingObjectTop position={props.position} />
    </g>
  );

  FlyingObject.propTypes = {
    position: PropTypes.shape({
      x: PropTypes.number.isRequired,
      y: PropTypes.number.isRequired
    }).isRequired,
  };

  export default FlyingObject;

error in console 控制台错误

bundle.js:38257 Uncaught TypeError: Object(...) is not a function
    at Object.<anonymous> (bundle.js:38257)
    at Object../node_modules/styled-components/dist/styled-components.browser.esm.js (bundle.js:39107)
    at __webpack_require__ (bundle.js:679)
    at fn (bundle.js:89)
    at Object../src/components/FlyingObject.jsx (bundle.js:41736)
    at __webpack_require__ (bundle.js:679)
    at fn (bundle.js:89)
    at Object../src/components/Canvas.jsx (bundle.js:41498)
    at __webpack_require__ (bundle.js:679)
    at fn (bundle.js:89)
    at Object../src/App.js (bundle.js:41128)
    at __webpack_require__ (bundle.js:679)
    at fn (bundle.js:89)
    at Object../src/containers/Game.js (bundle.js:42377)
    at __webpack_require__ (bundle.js:679)
    at fn (bundle.js:89)
    at Object../src/index.js (bundle.js:42462)
    at __webpack_require__ (bundle.js:679)
    at fn (bundle.js:89)
    at Object.0 (bundle.js:42872)
    at __webpack_require__ (bundle.js:679)
    at bundle.js:725
    at bundle.js:728

the index.js index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import './index.css';
import App from './containers/App';
import reducer from './reducers';
import registerServiceWorker from './registerServiceWorker';



/* eslint-disable no-underscore-dangle */
const store = createStore(
  reducer, /* preloadedState, */
  window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
);
/* eslint-enable */

ReactDOM.render(
  <Provider store={store}>
    <App/>
  </Provider>,
  document.getElementById('root'),
);
registerServiceWorker();

What is the solution? 解决办法是什么?

Thanks a lot. 非常感谢。

this is solved @garetmckinley Thanks. 这解决了@garetmckinley谢谢。

works fine if you install v3 如果你安装v3,工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM