How to run Redux DevTools Extension INSIDE Chrome Extension running React? - reactjs

The big issue i'm facing is I'm seeing the error "No store found" when trying to access my redux store in the Redux DevTools Extension WHILE my React app is running inside a Chrome Extension.
I've seen a few questions on SO about similar errors, like:
“No store found” when using Redux chrome extension"
"How to add Redux DevTools Extension to my react-redux store?"
Most of the answers to these questions relate to specifying the correct variables like using window.__REDUX_DEVTOOLS_EXTENSION__ instead of devToolsExtension (after the extension was upgraded), or installing the npm package redux-devtools-extension.
My problem is different - if I run my a React app (in development mode), outside of the Chrome Extension (a.k.a. not through the Chrome Extension's options page), I find that the Redux DevTools Extension works fine for me. However, as I mentioned before, when I run the React app from within the Chrome Extension options page, the Redux DevTools Extension cannot find the store.
Here is my index.js file that I use inside the options page:
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
import thunk from 'redux-thunk';
import App from './App';
import rootReducer from './store/reducers/root';
//
const composeEnhancers = process.env.NODE_ENV === 'development'
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
: null
|| compose;
const store = createStore(rootReducer, composeEnhancers(
applyMiddleware(thunk)
));
const app = (
<Provider store={store}>
<App />
</Provider>
);
ReactDOM.render(app, document.getElementById('root'));
I believe the error has to do with the fact that that I'm running the React App from within the options page of my Chrome Extension. I've found that window.__REDUX_DEVTOOLS_EXTENSION__ is undefined from the Chrome Extension options page, but that window.__REDUX_DEVTOOLS_EXTENSION__ variable is visible and accessible on normal pages. Is there any tried and tested way of making window.__REDUX_DEVTOOLS_EXTENSION__ available in the options page of a Chrome Extension?

You can use Remote Redux Devtools in this case.
Add this to your store creation (yarn add --dev remote-redux-devtools):
import devToolsEnhancer from "remote-redux-devtools";
const store = createStore(
popupReducer,
devToolsEnhancer({
hostname: "localhost",
port: 8000,
realtime: true
})
);
You will also need a remotedev server, I went with a local one:
yarn add --dev remotedev-server
cd /node_modules/.bin/
remotedev --port=8000
Now you can connect and monitor your store using the chrome extension, click the Remote button, go to settings and click "Use custom (local) server" there and you should see your store in realtime.

Related

react readux in Chome extension

I built a chrome extension with react.js and webpack.config.js . now I want add redux to my project but I don't know how to configure with redux
I just find the reduxed-chrome-storage npm package but I don't know how to configure
First, you need to install the dependencies for Redux and the reduxed-chrome-storage package:
npm install --save redux reduxed-chrome-storage
Create a store.js file where you will configure your Redux store. In this file, you will import the necessary dependencies and define the store.
import { createStore, applyMiddleware } from 'redux';
import storage from 'reduxed-chrome-storage';
const store = createStore(
rootReducer,
applyMiddleware(storage.middleware)
);
export default store;
Connect your React components to the Redux store by using the react-redux library. You will need to wrap your root component with the Provider component and pass the store as a prop.
import React from 'react';
import { Provider } from 'react-redux';
import store from './store';
function App() {
return (
<Provider store={store}>
{/* your application code */}
</Provider>
);
}
export default App;
Finally, you need to add the reduxed-chrome-storage enhancer to the store. This will allow the store to be persisted to Chrome storage:
import { createStore, applyMiddleware } from 'redux';
import storage from 'reduxed-chrome-storage';
const store = createStore(
rootReducer,
applyMiddleware(storage.middleware),
storage.enhancer
);
export default store;
This is the basic configuration for using Redux with your Chrome extension. You can now start using Redux in your application.

React Native - Expo update cause main no registered and tried to register two same name error

I have recently tried to update my React native application from expo 44 to 46 but it cause error
Here is my App.js
import React from 'react';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import ReduxThunk from 'redux-thunk';
import reducers from './src/reducers';
import Router from './src/Router';
export default class App extends React.Component {
render() {
const store = createStore(reducers, {}, applyMiddleware(ReduxThunk));
return (
<Provider store={store}>
<Router />
</Provider>
);
}
}
The error i am getting is:
Invariant Violation: Tried to register two views with the same name RNGestureHandlerButton
ERROR Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
Please find my github link
I believe expo docs are not clear on this:
Don't install react-native-gesture-handler,
it already exists in Expo.
If you are using Expo to build your react native app you do not have to import react-native-gesture-handler from npm or yarn. It is already in the expo package. If you import the package you will experience this error.
Also, you can check errors on github instead of directly posting question: https://github.com/software-mansion/react-native-gesture-handler/issues/451

React with Redux app only works if redux tools installed

I have built an app with react and redux. I build the app in the standard way.
npm run build --prod
The app is then deployed to firebase hosting. I found that the app will not load in Chrome, Firefox, or Safari unless the redux web dev tools are installed. Why is this and how can I stop it?
The app is at ... https://triviatime-e7aa2.web.app/
Configure redux dev tools with redux-devtools-extension npm package.
import { composeWithDevTools } from "redux-devtools-extension";
export const store = createStore(
rootReducer,
composeWithDevTools(applyMiddleware(...middleware))
);
See section 1.3 in following link for more information.
https://github.com/zalmoxisus/redux-devtools-extension#12-advanced-store-setup
Another option
import { createStore, applyMiddleware, compose } from 'redux';
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(reducer, /* preloadedState, */ composeEnhancers(
applyMiddleware(...middleware)
));

When using React Native Debugger, "Expected the reducer to be a function" happens

I was following a React Native tutorial.
I was trying to connect it to React Native Debugger app.
But then I got "Expected the reducer to be a function" error.
It says here that it is caused by {} around the module I'm importing.,
Expected the reducer to be a function
So I did fix it by removing {}
Basically, it works when import composeWithDevTools and it errors when import {composeWithDevTools} when connected to React Native Debugger.
But I cannot understand why!
The tutorial I'm following works totally fine with import {composeWithDevTools} when connected to React Native Debugger.
It works fine when NOT connected to React Native Debugger.
Is this an error on React Native Debugger? Why does this happen?
Edit: I re-started metro many times. It always produces the same result.
import { createStore, combineReducers } from 'redux';
import userReducer from './reducers/user';
import composeWithDevTools from 'redux-devtools-extension';
const rootReducer = combineReducers({
user: userReducer,
});
const store = createStore(rootReducer, composeWithDevTools);
export default store;
Turns out the error came from a different place than what the debugger pointed to.
Problem is here. const store = createStore(rootReducer, composeWithDevTools);
This should be
const store = createStore(rootReducer, composeWithDevTools());
with () added at the last argument.
It's good to follow documentation
You need the curly bracket. If it's behaviour is weird, or you have just installed a new package, maybe it's a good habit to restart the metro.

Redux devtools and React Native

I am working on a React Native app, but for some reasons I have the redux devtools not able to detect the store.
Here is the code for store.js
import { createStore, applyMiddleware, compose } from 'redux';
import createSagaMiddleware from 'redux-saga';
import jobs from './reducers/jobs';
import { watcherSaga } from './sagas';
// Saga Middleware
const sagaMiddleware = createSagaMiddleware();
const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
let store = createStore(jobs, composeEnhancer(applyMiddleware(sagaMiddleware)));
sagaMiddleware.run(watcherSaga);
// Enable Hot Module for the reducers
/* eslint-disable global-require */
if (module.hot) {
// module.hot.accept('./reducers/index', () => {
// store.replaceReducers(require('./reducers').default);
// });
}
export default store;
When I open the chrome debugger-ui I get "No store found" in the redux tab.
I already gave access to files url from the extension settings. I have no idea what can be the problem. I tried several store settings with middleware and redux-tools, found on tutorial, but none of them seems to work. I tried also the standalone app but it does not detect anything, neither the react code.
What am I doing wrong?
I found the solution and I share it so will help others.
The main problem is that I am using expo, so expo runs on a different port than the normal devtools.
Instead of using chrome I downloaded the standalone debugger and then, thanks to this article, I opened the debugger with the correct port, this did the magic:
rndebugger://set-debugger-loc?host=localhost&port=19001

Resources