使用开源软件包转换为新的类名

时间:2017-05-04 03:48:39

标签: javascript jquery html css reactjs

  • 我是js的新手。
  • 我正在尝试将我的添加类代码转换为此https://www.npmjs.com/package/classnames
  • bur当我尝试做的时候我没有得到正确的结果,你能告诉我如何解决它。
  • 在下面提供我的代码。
  • 即使我看到了示例但无法继续
**actual code**

Const swimmingName = 'sports-basketball' + (this.props.jumping ? ' jumping' : '');

**converted code**

let swimmingName = classnames({
    'sports-basketball' : true,
    'jumping' : this.props.jumping
});


Uncaught ReferenceError: classnames is not defined
    at PlayingSinging.render (swimming.jsx:20)
    at PlayingSinging.<anonymous> (makeAssimilatePrototype.js:15)
    at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js:587)
    at ReactCompositeComponentWrapper._renderValidatedComponent (ReactCompositeComponent.js:607)
    at ReactCompositeComponentWrapper.wrapper [as _renderValidatedComponent] (ReactPerf.js:66)
    at ReactCompositeComponentWrapper.mountComponent (ReactCompositeComponent.js:220)
    at ReactCompositeComponentWrapper.wrapper [as mountComponent] (ReactPerf.js:66)
    at Object.mountComponent (ReactReconciler.js:37)
    at ReactDOMComponent.mountChildren (ReactMultiChild.js:241)
    at ReactDOMComponent._createContentMarkup (ReactDOMComponent.js:591)

1 个答案:

答案 0 :(得分:0)

我认为你没有导入类名,所以你可以试试这个

import classnames from 'classnames'

let swimmingName = classnames({
  'sports-basketball' : true,
  'jumping' : this.props.jumping ? true : false
});