@brightleaf/react-hooks
Advanced tools
Comparing version 2.2.0 to 3.0.0
@@ -15,2 +15,4 @@ "use strict"; | ||
const reducer = (state, action, ...other) => { | ||
const messages = [].concat(state.messages); | ||
switch (action.type) { | ||
@@ -36,6 +38,5 @@ case 'connecting': | ||
case 'message': | ||
const message = [].concat(state.message); | ||
message.push(action.payload.data); | ||
messages.push(action.payload.data); | ||
return { ...state, | ||
message, | ||
messages, | ||
error: null, | ||
@@ -56,5 +57,5 @@ connecting: false | ||
const useNes = (url = 'ws://localhost:4567', subscribe = true) => { | ||
const useNes = (url = 'ws://localhost:4567', subscribe) => { | ||
const [state, dispatch] = (0, _react.useReducer)(reducer, { | ||
message: [], | ||
messages: [], | ||
error: null, | ||
@@ -71,4 +72,4 @@ connecting: true, | ||
}); | ||
return new Promise(async (resolve, reject) => { | ||
client.onConnect = update => { | ||
return new Promise(async resolve => { | ||
client.onConnect = () => { | ||
dispatch({ | ||
@@ -100,3 +101,3 @@ type: 'connected' | ||
if (subscribe) { | ||
client.subscribe(url, update => { | ||
client.subscribe(subscribe, update => { | ||
dispatch({ | ||
@@ -103,0 +104,0 @@ type: 'message', |
{ | ||
"name": "@brightleaf/react-hooks", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "Useful react hooks", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -300,3 +300,3 @@ # Brightleaf React Hooks | ||
const { message, error, connecting, connected } = useNes( | ||
const { messages, error, connecting, connected } = useNes( | ||
'wss://kev-pi.herokuapp.com' | ||
@@ -311,7 +311,7 @@ ) | ||
const messages = message.map((m, index) => <div key={`key-${index}`}>{m}</div>) | ||
const messageList = messages.map((m, index) => <div key={`key-${index}`}>{m}</div>) | ||
return ( | ||
<div className="App"> | ||
<h1>Messages from Server</h1> | ||
<div>{messages}</div> | ||
<div>{messageList}</div> | ||
<div> | ||
@@ -318,0 +318,0 @@ <b>Status Messages</b> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118775