问题
- 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