debugged the code I think it will be this function onSelect

人走茶凉 提交于 2019-12-24 02:27:08

问题


  • 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.

    providing code below

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

回答1:


I've created a working solution here: JSFiddle

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);    

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



来源:https://stackoverflow.com/questions/43669937/debugged-the-code-i-think-it-will-be-this-function-onselect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!