Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the color of a Link in React with Material-UI?

I'm not able to change the color of a Link inside a Button. When I apply the secondary color to the Button, it doesn't take effect. In other components it does work this way.

<AppBar position='fixed'>
                <Toolbar>
                    <Button color='secondary'>
                        <Link to="/">Home</Link>
                    </Button>
                </Toolbar>
</AppBar>

In App.js I create the custom Theme and wrap it around all components with <ThemeProvider theme={customTheme}>

App.js:

const customTheme = createMuiTheme({
    palette: {
        primary: {
            main: '#36454B',
            contrastText: '#fff',
        },
        secondary: {
            light: '#55dab3',
            main: '#00a883',
            dark: '#007856',
            contrastText: '#000',
        }
    }
});
like image 221
Nadine Avatar asked Dec 12 '19 14:12

Nadine


People also ask

How do I add a link in material UI icon?

How do I add a link in material UI icon? First make sure you have added Material Icon library. If this library is added just add the HTML css class insert_link to any element to add the icon. Material Design Insert Link Icon can be resized as per your need.

How do I change the color of a div in React?

Conditional Changing the Background Color in Reactimport React from 'react'; import './App. css'; function App() { const isBackgroundRed = true; return ( <div className={isBackgroundRed ? 'background-red' : 'background-blue'} /> ); } export default App; JSX allows us to write JavaScript inside of HTML.


1 Answers

What you can do is pass component={Link} to button, so it will render the Link as it base component. See the docs.

<Button color='secondary' href="/" component={Link}>
    Home
</Button>
like image 89
Vencovsky Avatar answered Sep 24 '22 00:09

Vencovsky