Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Is there a minimal example for gw2-ui? #5

Open
acbetter opened this issue Jan 21, 2021 · 2 comments
Open

Is there a minimal example for gw2-ui? #5

acbetter opened this issue Jan 21, 2021 · 2 comments

Comments

@acbetter
Copy link

I tried to use gw2-ui in my react next.js repo, but i can't fix it because of redux issues. Here's my code, help

next-redux-thunk-example.zip

image

@ManuelHaag
Copy link
Owner

For now, you can refer to the gw2-ui-docs package source code.

You'll want to create your redux store similar to this:

import { handleRequests } from 'gw2-ui';
import { applyMiddleware, combineReducers, compose, createStore } from 'redux';
const { requestsReducer, requestsMiddleware } = handleRequests();
const reducers = combineReducers({
requests: requestsReducer,
});
const composeEnhancers =
(typeof window !== 'undefined' &&
// eslint-disable-next-line no-underscore-dangle
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
compose;
export default () => {
const store = createStore(
reducers,
composeEnhancers(applyMiddleware(...requestsMiddleware)),
);
return store;
};

and wrap your app like this:

import { Provider } from 'react-redux';
import { ThemeProvider, baseTheme } from 'gw2-ui';
import createStore from './createStore';

const store = createStore();

// ...
  <Provider store={store}>
    <ThemeProvider theme={baseTheme}>
      <App/>
    </ThemeProvider>
  </Provider>
// ...

Then you can use the components as in the gw2-ui Storybook - check the right panel's tabs for available props.

@acbetter
Copy link
Author

Thanks for the reply and it worked very well for me. Very thanks! I'm not familiar with react-redux...

Now here I get another question, MistlockInstability is fine for me but when I try to use skill template then getUncaught TypeError: Cannot read property 'FETCH_SKILL14375' of undefined error.

import './App.css';
import { Skill } from "gw2-ui";
import { MistlockInstability } from 'gw2-ui';

function App() {
  return (
    <div className="App">
      <Skill id={14375} />
      <MistlockInstability name="Adrenaline Rush" />
    </div>
  );
}

export default App;

I think it's a prop type issue so I tried to use int(number) prop but didn't work. I tried to look up the source code of Skill component but I can't understand it very well.

Here's my code, one with next.js and the other use pure react code. Both got the same exception.

next-gw2-ui-example.zip
react-gw2-ui-example.zip

image
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants