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

Tokens: fix dark mode header #1059

Merged
merged 2 commits into from
Dec 21, 2019
Merged

Tokens: fix dark mode header #1059

merged 2 commits into from
Dec 21, 2019

Conversation

sohkai
Copy link
Contributor

@sohkai sohkai commented Dec 21, 2019

We were using useTheme() before Main was declared, leading to the theme not being reactive to the appearance set.

In general, I wonder if we should make it a rule that Main is used ahead of any other app logic, to avoid cases like this? For example, both Finance and Voting could fall into this trap if they were to use useTheme() in their App.js.

Copy link
Contributor

@bpierre bpierre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were using useTheme() before Main was declared, leading to the theme not being reactive to the appearance set.

Well found! 🙌

In general, I wonder if we should make it a rule that Main is used ahead of any other app logic, to avoid cases like this? For example, both Finance and Voting could fall into this trap if they were to use useTheme() in their App.js.

Yes we should probably try to move it to index.js or to the App wrapper component, with the other providers. But the problem is that it also requires to be at another level than AragonApi so we can use its hook.

I’m wondering if we shouldn’t throw an error if useTheme is used outside of Theme? It would prevent cases like this one that can be hard to debug.

I’m also thinking that AragonApi could optionally provide a render prop, or perhaps we could only do that for the aragonUI connector, as a dedicated component?

It would allow to declare both the aragonAPI and aragonUI providers in the same component:

import { AragonApiAragonUi, useAragonApi } from '@aragon/api-react'
import { Main } from '@aragon/ui'

function App() {
  const theme = useTheme()
  const api = useAragonApi()
  return (
    // …
  )
}

export default () => (
  <AragonApiAragonUi>
    {connector => (
      <Main connector={connector}>
        <App />
      </Main>
    )}
  </AragonApiAragonUi>
)

Or we could provide a helper function:

import { connectAragonUi, useAragonApi } from '@aragon/api-react'
import { Main } from '@aragon/ui'

function App() {
  const theme = useTheme()
  const api = useAragonApi()
  return (
    // …
  )
}

export default connectAragonUi(connector => (
  <Main connector={connector}>
    <App />
  </Main>
))

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 97.816% when pulling db01663 on tokens-dark-header into d2b9daf on master.

@sohkai
Copy link
Contributor Author

sohkai commented Dec 21, 2019

I’m wondering if we shouldn’t throw an error if useTheme is used outside of Theme? It would prevent cases like this one that can be hard to debug.

Yes! Or at least a warning :).


I really like the connector function!

@sohkai sohkai merged commit b56258a into master Dec 21, 2019
@sohkai sohkai deleted the tokens-dark-header branch December 21, 2019 19:14
MickdeGraaf pushed a commit to MickdeGraaf/aragon-apps that referenced this pull request Jan 28, 2020
ramilexe pushed a commit to ConsiderItDone/aragon-apps that referenced this pull request Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants