Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable plugin dynamically #9

Closed
ghost opened this issue Jun 17, 2019 · 3 comments
Closed

Disable plugin dynamically #9

ghost opened this issue Jun 17, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented Jun 17, 2019

Can I disable and enable the plugin dynamically? I tried this command but it didn't work.

jss.use(rtl({ enabled: false }));

@alitaheri
Copy link
Owner

alitaheri commented Jun 18, 2019

@hadiranjbar25 I'm not sure what your use-case is. But if you're going to disable the entire plugin you better render the entire page anew too. in other words, you need to unmount React, build jss again and then re-render the entire tree again. because changing this dynamically will leave a lot of dangling states around your app.

https://reactjs.org/docs/react-dom.html#unmountcomponentatnode

it shouldn't be hard to re-render the entire tree. something like this:

const container = document.getElementById('root');

function renderWithRTL(rtl = false) {
  ReactDOM.unmountComponentAtNode(container);

 const jss = create();
 jss.plugins = rtl ? [/* plugins including rtl*/] : [/* plugins without rtl */];

 ReactDOM.render(<JssProvider jss={jss}><App></JssProvider>, container);
}

then, you can call renderWithRTL with true/false values to re-render the entire app in rtl/ltr

@ghost
Copy link
Author

ghost commented Jun 18, 2019

I want to change the entire style with one click. If it's not possible, your solution seems good. Thank you.

@alitaheri
Copy link
Owner

@hadiranjbar25 if you're using a themeing solution or material-ui. you can try changing the theme of material-ui or set the rtl on whatever themeing solution you have. and then further down the tree use the value from the theme to switch the flip property of each stylesheet. if not then this is the best you can get, jss isn't designed to have plugins change initial config dynamically.

P.S. it can still be one click without having to refresh. might just take a couple of microseconds to re-render the whole app, depending on how heavy it is.

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

No branches or pull requests

1 participant