调试了代码,我认为它将是onSelect的此功能 [英] debugged the code I think it will be this function onSelect

查看:94
本文介绍了调试了代码,我认为它将是onSelect的此功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我在React类中有工作代码
  • 但是当我更改为React.Component时,整个UI都崩溃了.
  • 调试了代码,我认为问题在于此功能onSelect .
  • 因为如果我给控制台语句不打印任何内容.
  • 你能告诉我如何解决它吗?
  • 我什至检查了css是否相同.

  • I had working code in react class
  • but when I changed to React.Component the whole UI is breaking.
  • debugged the code I think problem will be this function onSelect.
  • since if I give console statements its not printing anything.
  • can you tell me how to fix it.
  • i even checked the css it is same.

在下面提供代码

class Accordion extends React.Component {
  constructor(props) {
    super(props);

推荐答案

我在这里创建了一个可行的解决方案: JSFiddle

I've created a working solution here: JSFiddle

似乎React.cloneElement在分配的道具上添加了修饰符.因此,与其使用道具"_onSelect",不如使用"$ Accordion"

It seems that React.cloneElement prepends a modifier onto the props that are assigned. So instead of having a prop "_onSelect", it is being prepended by "$Accordion"

对这些道具的工作函数调用如下:

A working function call on those props looks like this:

this.props.$Accordion_onSelect(this.props.id);    

要删除$ Accordion附加内容,请不要在下划线前启动prop键.如果只是"onSelect",那么它将作为"onSelect"传递.这是 JSFIddle

To remove the $Accordion addition, don't start the prop key with an underscore. If it's just 'onSelect' then it will be passed as 'onSelect'. Here's the JSFIddle

这篇关于调试了代码,我认为它将是onSelect的此功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆