Skip to content

Front-end can't connect to server in prod. react-scripts, nginx, strapi (nodejs) #4493

Answered by antokhio
antokhio asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks to @eskimojo from redux channel the issue finally sorted

the middleware action matcher was firing before the reducer, so at the moment of subscription creation socket was not initialized...
the solution was to move socket creation outside of reducer

import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { Middleware } from "redux";
import { io, Socket } from "socket.io-client";

type SocketState = {
  connected: boolean;
};

let socket: Socket;

export const getSocket = () => {
  if (socket) return socket;
  return null;
};

const slice = createSlice({
  name: "socket",
  initialState: {
    connected: false,
  } as SocketState,
  reducers: {
    connect: (state, { p…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by antokhio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant