-
Notifications
You must be signed in to change notification settings - Fork 5
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
Comments
@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 |
I want to change the entire style with one click. If it's not possible, your solution seems good. Thank you. |
@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. |
Can I disable and enable the plugin dynamically? I tried this command but it didn't work.
jss.use(rtl({ enabled: false }));
The text was updated successfully, but these errors were encountered: