Comments (4)
I am no React dev myself, but what I did is
npx create-react-app my-app
Then I installed emitter with nmp install emitter-io
Then I modified the app.js to obtain the following :
(sorry for the format, it's not me, it's github)
`
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
var emitter = require('emitter-io')
class App extends Component
{
constructor(props)
{
super(props)
//this.someFunction = this.someFunction.bind(this)
let client = emitter.connect();
client.subscribe({
key: "YgBLv3zD4e2Vz_jdZUR1ojZlJiABlhTD",
channel: "test"
});
client.on('message', function(msg){
console.log( msg.asString() );
});
// publish a message to the chat channel
client.publish({
key: "YgBLv3zD4e2Vz_jdZUR1ojZlJiABlhTD",
channel: "test",
message: "hello, emitter!"
});
}
render() {
return (
...
`
And this works fine. But maybe I'm not using React the proper way? Tell me more about how you do it...
from javascript.
Not sure I understand the issue... You can register any function in client.on('message')
, including an arrow function of the component. From this arrow function, can't you just do this.setState({...})
?
from javascript.
how to pass message to state?
from javascript.
thanks man, it works using an arrow function
from javascript.
Related Issues (9)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javascript.