jkzing / vscode-redux-devtools

Redux DevTools vscode extension
MIT License
81 stars 10 forks source link

does it work in RN with Redux toolkit ? #48

Closed skurgansky-sugarcrm closed 1 year ago

skurgansky-sugarcrm commented 1 year ago
import {configureStore} from '@reduxjs/toolkit';
import devToolsEnhancer from 'remote-redux-devtools';
let store = configureStore({
  reducer: persistedReducer,
  middleware(getDefaultMiddleware) {
    return getDefaultMiddleware({
      serializableCheck: {
        ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
      },
    })
      .prepend(api.middleware)
      .concat(rtkQueryErrorLogger);
  },
  devTools: false,
  enhancers: [
    devToolsEnhancer({
      realtime: true,
      port: 8081,
    }),
  ],
});

websocket do not connect ...

skurgansky-sugarcrm commented 1 year ago

i managed to connect via "@redux-devtools/cli": "^2.0.0", but connection is not stable ... it disconnects and reconnects all the time

npx redux-devtools --hostname 127.0.0.1 --port 8000

then RN

import {configureStore} from '@reduxjs/toolkit';
import devToolsEnhancer from 'remote-redux-devtools';

const composeEnhancers = composeWithDevTools({
  realtime: true,
  hostname: '127.0.0.1',
  port: 8000,
  name: Platform.OS,
  ...Platform.select({
    ios: {
      maxAge: 1000,
      latency: 2000,
      autoPause: true,
    },
    android: {
      maxAge: 500,
      latency: 1000,
      autoPause: false,
    },
  }),
});

let store = configureStore({
  reducer: persistedReducer,
  middleware(getDefaultMiddleware) {
    return getDefaultMiddleware({
      serializableCheck: {
        ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
      },
    })
      .prepend(api.middleware)
      .concat(rtkQueryErrorLogger);
  },
  devTools: false,
  enhancers: defaultEnhancers => [composeEnhancers(...defaultEnhancers)],
});

then i tried vscode redux devtools and browses extention for Redux DevTools. All the same. No stable connection yet. not even 5 seconds before it falls

skurgansky-sugarcrm commented 1 year ago

It looks like remote-redux-devtools obsolete package? Documentation is a mess. We need to go on with @redux-devtools/remote.

Here is working example for RN project:

  1. install packages :
    "@redux-devtools/cli": "^2.0.0",
    "@redux-devtools/remote": "^0.8.0",
    "react-native-get-random-values": "^1.8.0"
    don't forget `cd ios & pod install` for react-native-get-random-values. 
  2. in root directory in index.js add
    // fix: https://www.npmjs.com/package/uuid#react-native--expo
    import 'react-native-get-random-values';

    without it your app will throw error with crypto.getRandormSomething..

  3. Run your dev server for remote redux dev tools: redux-devtools --open=electron --hostname=localhost --port=8000. Maybe you will need to install electron.
  4. optional: add script for package.json:
    "postinstall": "redux-devtools --open=electron --hostname=localhost --port=8000"
  5. Go with this code or something similar
    
    import {devToolsEnhancer} from '@redux-devtools/remote';

let store = configureStore({ reducer: rootReducer, // middleware: [], // your middleware devTools: false, enhancers: [ devToolsEnhancer({ name: 'myReduxApp', realtime: true, hostname: '192.168.1.122', // IP address of machine where redux-devtools server is running port: 8000, trace: true, traceLimit: 10, }), ], });