tshaddix / webext-redux

A set of utilities for building Redux applications in Web Extensions.
MIT License
1.22k stars 180 forks source link

How do we use webext-redux with react hooks? #226

Closed ulvido closed 4 years ago

ulvido commented 4 years ago

old way works fine but I coun't get it work with hooks. does webext support hooks?

App.jsx

"use strict";

import React from "react";
import { useSelector, useDispatch } from "react-redux";

const App = props => {
  const count = useSelector(state => state.count);
  return (
    <div><h1>{count}</h1></div>
  );
};

export default App;

index.js

"use strict";

import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { Store } from "webext-redux";
import App from "./App.jsx";

// PROXYSTORE
const proxyStore = new Store({
  state: {},
  portName: "myport"
});

proxyStore.ready().then(() => {
  ReactDOM.render(
    <Provider store={proxyStore}>
      <React.StrictMode>
        <App />
      </React.StrictMode>
    </Provider>
    , document.getElementById("root")
  );
ulvido commented 4 years ago

ok figured it out. you need to call with your reducer which you combined like this. const count = useSelector(state => state.counterReducer.count);

nothing about webext.