Skip to content

Instantly share code, notes, and snippets.

@pffigueiredo
Created August 9, 2021 17:08
Show Gist options
  • Save pffigueiredo/1ae6121c1b1505c5212c14db27d2a03d to your computer and use it in GitHub Desktop.
Save pffigueiredo/1ae6121c1b1505c5212c14db27d2a03d to your computer and use it in GitHub Desktop.
_app file using stylis plugin
import React from 'react';
import { AppProps } from 'next/app';
import { StyleSheetManager } from 'styled-components';
import { StylisPlugin } from 'styled-components';
import stylisRTLPlugin from 'stylis-plugin-rtl';
import { useTranslation } from 'react-i18next';
const App = (props: AppProps): JSX.Element => {
const { Component, pageProps, router } = props;
const { locale } = router;
const { i18n } = useTranslation();
// Get direction based on locale
const direction = i18n.dir(locale);
return (
<StyleSheetManager
stylisPlugins={
direction === 'rtl' ? [stylisRTLPlugin as unknown as StylisPlugin] : []
}
>
<Component {...pageProps} />
</StyleSheetManager>
);
};
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment