I have a HOC
import React from 'react'
class Func extends React.Component {
addItem = () => {
console.log('clicked')
}
render(){
const style = {
background: 'lightgrey',
margin: '1rem'
}
return (
<div style={style}>
{this.props.children}
</div>
)
}
}
export default Func
an I have a HOC's child
import React from 'react'
import Func from './Func'
const AddButton = (props) => {
return (
<Func>
<button onClick={props.addItem}>
ok
</button>
</Func>
)
}
export default AddButton
I'd like to pass that function (and maybe somewhat else) into child and call it here.
I see child have a nice grey background, so I think props are there.
But I see in react devtools any traces of function passed to it (Props read-only Empty object
). So clicking does not lead to anything. ((
If background is already there, so where is a function?