Andrew Kloos
Andrew Kloos

Reputation: 4608

Getting func.call is not a function in React while trying to call a Node.js function. What's my problem?

I have a Node.js function utilizing sockets on another React page which is working correctly removing users from a queue. I'm trying to implement that function on another page but I keep getting func.call is not a function. Here's the problematic React:

class Stations extends Component {

static propTypes = {
className: PropTypes.string,
queue: PropTypes.array,
Remove: PropTypes.func,
}

Remove = (station, index) => {
   this.socket.on('removeUser', {station, index});
}

render() {
    const { className, queue } = this.props

return (
...
   <Button as={Label} color="red" className="deleteLabel" size="tiny" onClick="{this.Remove(station, index)}">Remove</Button>
...

Upvotes: 0

Views: 155

Answers (1)

cbr
cbr

Reputation: 13662

onClick should be a function:

onClick={() => this.Remove(station, index)}

Additionally, if you meant to send a message over socket instead of adding a new event listener, you probably meant emit:

this.socket.emit('removeUser', {station, index});

Upvotes: 1

Related Questions