v1.1.0
Add a possibility to not start a connection immediately
Example
Create signalMiddleware with shouldConnectionStartImmediately set to false.
const signal = signalMiddleware({
callbacks,
connection,
shouldConnectionStartImmediately: false
});
Then, import the 'connection' in the place you want and start it if it's not already.
Here is an example with a simple Button container:
import { connection } from "../redux/helpers/createSignalMiddleware";
const StartConnectionButton: FunctionComponent = () => {
const handleClick = useCallback(() => {
if (connection.state !== HubConnectionState.Connected) {
connection
.start()
.then(() => console.log("Connection started"))
.catch((err) => console.error(err.toString()));
}
}, []);
return <Button onClick={handleClick}>Start Connection</Button>;
};
export default StartConnectionButton;