Skip to content

Undefined $this within pusher-js when rendering Pusher component #18

@natembennett

Description

@natembennett

When I try to render a Pusher component, I receive this error:

TypeError: Cannot set property 'key' of undefined

Pusher
node_modules/pusher-js/dist/web/pusher.js:155

  152 |   logger_1["default"].warn("You should always specify a cluster when connecting. " + suffix);
  153 | }
  154 | 
> 155 | this.key = app_key;
      | ^  156 | this.config = Collections.extend(DefaultConfig.getGlobalConfig(), options.cluster ? DefaultConfig.getClusterConfig(options.cluster) : {}, options);
  157 | this.channels = factory_1["default"].createChannels();
  158 | this.global_emitter = new dispatcher_1["default"]();

My implementation:

import Pusher from 'pusher-js';
import { setPusherClient } from 'react-pusher';
    constructor(props){
        super(props);
        this.pusherClient = new Pusher("bf5df34b3b535a270b0a", {
            cluster: "us2",
        });
    }
    render(){
        setPusherClient(this.pusherClient);
        return (
            <Flexbox>
                <Pusher
                    channel="someChannel"
                    event="listChanged"
                />
            </Flexbox>
        )
    }

I'm assuming this is due to instantiating setPusherClient incorrectly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions