Our libraries work with client side rendered React apps.
Vite has a problem with libraries that use Globals. Our libraries use Globals.
<script> window.global = window</script>
Vite doesn't have access to process.env - so if you bring in a library that's looking for a process env variable - Vite wants you to import everything through import.meta
Let's simplify App.tsx in preparation for the DAOhaus libraries. Replace the contents of App.tsx with the following.
And delete import './index.css' from main.tsx
Load the page and you should see an unstyled "Hello World" in the top left corner.
The DAOhaus UI package provides a theme and various UI components to help you quickly build your new DAO app. This UI library is best when building a new app and shouldn't be used within existing apps (TODO: Because why?)
Install the UI library with this command:
yarn add @daohaus/ui
Open main.tsx and add to the top:
import {HausThemeProvider} from '@daohaus/ui';
and wrap your <App />
tag with <HausThemeProvider>
main.tsx should look like this:
Refresh the app and you will see the app is now in dark mode, with the default text styling.
HausThemeProvider has parameters.
TODO: How do I get all of the parameters for HausThemeProvider?
Return to App.tsx and wrap your "Hello World" in a <MainLayout>
and <H1>
tag.
TODO: Are there other layouts? How are they configured, where are the layout docs?
This library includes many React dependencies under the hood. This includes React Router and React Hook Form.
Because of this, we can easily install HashRouter (which will later help us deploy onto an IPFS based deployment).
add import {HashRouter} from 'react-router-dom';
to main.tsx
Look in your node_modules folder and note that react-router-dom
is already included in the app as a consequence of installing @daohaus/ui
The same is true of react-hook-form
If you don't end up using these in your app, it will be optimized out when you deploy your app.
Let's add a "WrappedInput" tag to get some input from the user. WrappedInput comes from the @daohaus/ui library, but it requires the FormProvider context from 'react-hook-form', which requires useForm.
Modify your App.tsx to match the following:
import the DAOhaus connect library
yarn add @daohaus/connect
This will connect you to an RPC, allowing you to use things like MetaMask. It will also pull down your DAOhaus profile, handling your ENS fetches, eventually your LENS protocol fetch and bringing that into the application relatively easily.
Every time we layer a context into the base level, these contexts share data to the rest of your application. This means we can go into App.tsx and import elements.
Lets try this by importing the DAOhaus Nav bar.
Add <DaoHausNav />
inside of <FormProvider
tag in App.tsx
This will automatically add authentication functionality to your app.
Let's go one step further. Instead of adding DaoHausNav manually, let's bring DHLayout. This will give us DAOHausNav and menu functionality together.
Change your import:
import {DHLayout} from '@daohaus/connect'
Wrap your <MainLayout />
tag with <DHLayout>