Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
how to use theme in just one component directly without App.tsx? reactjs typescript

I have a context and theme to apply in a components lib, these components need to apply that theme. The client repository will choose the theme, but how do I make my components use the theme in the lib repository without the ThemeProvider in App.tsx that does not exist in libs?

my button.tsx:

const ButtonCircular = (props: ButtonCircularProps) => (
  <Container {...props}>
   {children}
  </Container>
);

const Container = styled.button`
  width: {use theme};
  height: {use theme};
  display: flex;
  justify-content: center;
  align-items: center;
  border: none;
`;

my theme.ts

 export const lightTheme: IThemeProps = {
  primary: "#FFF",
  secondary: "#F8F8F8",
  textColor: "#585280",
  header: "#585280",
  headerNumber: "#FFF",
  activeMenu: "#585280"
};

export const darkTheme: IThemeProps = {
  primary: "#302C40",
  secondary: "#2C2839",
  textColor: "#FFF",
  header: "#FFF",
  headerNumber: "#585280",
  activeMenu: "#FFF"
};

my context.ts

import { createContext, useContext } from "react";

export enum Theme {
  LightTheme,
  DarkTheme,
}

export type ThemeContextType = {
  theme: Theme;
  setTheme: (Theme: Theme) => void;
};

export const ThemeContext = createContext<ThemeContextType>({
  theme: Theme.LightTheme,
  setTheme: (Theme) => console.warn("No theme provider"),
});

export const useTheme = (): ThemeContextType =>
  useContext<ThemeContextType>(ThemeContext);
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda