0.1.3 • Published 2 years ago
embed-app v0.1.3
Getting Started
Create React App Project
npx create-react-app my-app
Create Client
- Redirect Url : http://localhost:3000
Install Package
yarn add @haravan/reactapp
Add Provider App
const localeTranslations = {
vi: {
title: "Việt Nam",
},
en: {
title: "Viet Nam",
},
};
root.render(
<AppProvider
options={{
client_id: "5ea59355ba662ac8b1dba617a09dc85e",
identity: "https://accounts.hara.vn",
response_type: "code",
scope: "openid email org com.read_orders",
}}
translations={locales}
fallbackLocale={"vi"}
>
<App />
</AppProvider>
);
Add Provider For EmbbedApp
const localeTranslations = {
vi: {
title: "Việt Nam",
},
en: {
title: "Viet Nam",
},
};
root.render(
<EmbedAppProvider
options={{
client_id: "7ca59d8a0181c43fd86bebc666933687",
myharavan: "sku.vn",
installUrl: "http://localhost:5000/auth/install",
autoRedirectInstall: false,
}}
translations={locales}
fallbackLocale={"vi"}
>
<EmbbedApp />
</EmbedAppProvider>
);
Use user, signin, signout in App
const { signin, signout, user } = useApp();
const fetchJson = useFetchJson();
const t = useTrans();
Use state, gotoInstall when state === NotInstalled EmbbedApp
const { state, gotoInstall } = useEmbbedApp();
const fetchJson = useFetchJson();
const t = useTrans();
...
const msg = t('title')
if(state == AppState.NotInstalled) {
gotoInstall()
}
fetchJson('https://abc.com/me.json')
Use Swr
import useSWR from "swr";
const { data } = useSWR("https://abc.com/me.json");
Use FetchJson & FetchData & Transalate
const fetchJson = useFetchJson();
const fetchData = useFetch();
const t = useTrans();