How to use google fonts in styled components

Solution To use google fonts in styled components, you have to download google font and save your in project font directory.Then use react import statement to import font file and use it in your style css. For google font, first of all you have to type google font on google. Here choose the font of your choice, Select its boldness and italic. When you copy the google font link, put it within the <head> section of your index....

January 4, 2023 · 2 min · The Unknown Developer

How to use loader in styled components

Solution To use and create a loader in styled components, you can use animation and @keyframes it will create ui which rotates 360 deg and look like as a loader. Snippet In this snippet, we will use styled components, with animation, @ Keyframes, and -WebKit to make styled loader components. const Loader = styled.div` display: inline-block; width: 50px; height: 50px; border: 3px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: #ffffff; animation: spin 1s ease-in-out infinite; -webkit-animation: spin 1s ease-in-out infinite; @keyframes spin { to { -webkit-transform: rotate(360deg); } } @-webkit-keyframes spin { to { -webkit-transform: rotate(360deg); } }`; Example In this example, we will styled componets library and create loader using styled css with animation, @keyfrem, -WebKit....

January 3, 2023 · 2 min · The Unknown Developer

How to override css in styled components

Solution To override css in styled components, you have to pass styled css component in styled function and override any css property. Snippet In this snippet, we will create button styled component and override his css property in primary button styled components. const Button = styled.button` border-radius: 3px; border: none; color: black; background: white; `; const PrimaryButton = styled(Button)` color: white; background: blue; `; Example n this example, we will styled componets library and create to styled components button and primary button, in primary button styled components....

January 2, 2023 · 1 min · The Unknown Developer

How to use css variables in styled components

Solution To use css variables in styled components, same as in CSS use --main-color with a variable name to create variables and use var function with variables name. Snippet In this snippet, we will import styled components library and create buttons using styled components, then create --main-color variables as a blue and use --main-color variables in button color using var function. const Button = styled.div` --main-color: blue; color: var(--main-color); &:hover { color: red; } Example In this example, we will create styled componets library and Button component has a custom property (--main-color) with a value of blue and variable color (--main-color) click on hover then change the color of red....

January 1, 2023 · 1 min · The Unknown Developer

How to use keyframes in styled components?

Solution To use keyframes in styled components, we have use slide keyframes and MovingButton. Snippet In this snippet, we will see how to use keyframes in styled components and slide animation at three different points during the animation. First-line animation defines 0% transform and second-line animation defines 50% transform and third-line animation defines 100% transform. const slide = keyframes` 0% { transform: translateX(0) } 50% { transform: translateX(150%) } 100% { transform: translateX(0) } `; Example In this example, we will create styled components as the animation button and we will pass slide animation as defined using a keyframes block....

December 31, 2022 · 1 min · The Unknown Developer

How to set value in input type date in React js?

Solution To set value in input type date in React, pass your date into value attribute of input type date. it will show your pass date as a selected date. To format a date you can read my below article, here I have explained multiple ways to format a date. https://reactjssnippet.com/posts/how-to-display-date-in-react-js/ Snippet In this snippet, we will see short example to set value in input type date. <input type="date" onChange={(e) => setDate(e....

December 30, 2022 · 1 min · The Unknown Developer

How to use media query in styled components?

Solution To use media query in styled components, you can use @media syntax in styled CSS. check out the below Snippet and Example. Snippet In this snippet, we will see how to use media query in styled components and when we will use media query displaying min-width: 768px.Then our webside will look responsive. const Header = styled.header` padding: 10px; margin: 0 auto; @media (min-width: 768px) { margin: 0; display: flex; justify-content: space-between; align-items: center; ul > li { display: inline-block; margin: 0 4px; } } `; Example In this example, we will create styled components as the styled-header....

December 30, 2022 · 1 min · The Unknown Developer

How to convert date to UTC in React js?

Solution To convert date to UTC in React, use toISOString() method it will convert date to UTC and return utc date string. To format a date you can read my below article, here I have explained multiple ways to format a date. https://reactjssnippet.com/posts/how-to-display-date-in-react-js/ Snippet In this snippet, we will see short example to convert date into utc date. // Current Date to UTC Date const ISOdate = new Date().toISOString(); console.log("Current Date to UTC: ", ISOdate) // Current Date to UTC: 2022-12-29T13:42:30....

December 29, 2022 · 1 min · The Unknown Developer

How to get day from date in React js?

Solution To get day from date in React, you can use the getDay() method it will return number between 0 to 6, with 0 representing Sunday, 1 representing Monday, and so on. To format a date you can read my below article, here I have explained multiple ways to format a date. https://reactjssnippet.com/posts/how-to-display-date-in-react-js/ Snippet In this snippet, we will see short example to get day from date in react js....

December 28, 2022 · 1 min · The Unknown Developer

How to use hover in styled components?

Solution To use hover in styled components, you have use &:hover syntax in styled CCS. check out the below Snippet and Example. Snippet In this snippet, we will see how to use hover in styled components and then hover is used when the mouse is clicked on a text or button and its color changes. &:hover { background-color: pink; } Example In this example, we will create styled components as the button and we will &:hover pseudo-class only works for elements that can be hovered over, such as links, buttons, and other interactive elements....

December 28, 2022 · 1 min · The Unknown Developer

How to get current date in React js?

Solution To get current date in React, you can use the new Date() object it will return current date & time based on system timezone. To format a date you can read my below article, here I have explained multiple ways to format a date. https://reactjssnippet.com/posts/how-to-display-date-in-react-js/ Snippet In this snippet, we will see short example to genrate current date in react js. const date = new Date(); console.log("Date", date.toLocaleDateString()) // 12/27/2022 Example In this example, we will write a react js code to get current date and show in the React UI....

December 27, 2022 · 1 min · The Unknown Developer

How to pass props in styled components?

Solution To pass props in styled components, you have to mention attributes in your style tag, then can you use those attributes as a props in your style CSS. Snippet In this snippet, we will see how to pass props in styled components and then how can the use style component. const Button = styled.button` /* Adapt the colors based on primary prop */ background: ${props => props.primary ? "palevioletred" : "white"}; color: ${props => props....

December 27, 2022 · 1 min · The Unknown Developer

How to add image in styled components?

Solution To add image in styled components, sets the styled img element with the src attribute set to the file logo192.png and the alt attribute set to a descriptive string. Snippet In this snippet, we will see how to add image in styled components and the styled img element with the src attribute set to the file logo192.png. const StyledImg = styled.img` height: 200px; width: 200px; border-radius: 50%; object-fit: cover; `; <StyledImg src="logo192....

December 26, 2022 · 1 min · The Unknown Developer

How to disable future date in datepicker in React js?

Solution To disable future date in datepicker in React, you can use the max attribute you have to just pass your date in YYYY-MM-DD. Note: Your date should formated like this YYYY-MM-DD. To format a date you can read my below article, here I have explained multiple ways to format a date. https://reactjssnippet.com/posts/how-to-display-date-in-react-js/ Snippet In this snippet, we will see short example to disable future date using max attribute. <input type="date" onChange={(e) => setDate(e....

December 26, 2022 · 1 min · The Unknown Developer

How to use classname in styled components?

Solution To use classname in styled components, you have to mention attributes in your style tag, then can you use those attributes as a prop in your style CSS. Snippet In this snippet, we will see how to use classname in styled components and headercomp use is classname and title. export const HeaderComp = ({ className, title }) => { return ( <header className={className}> <h2>{title}</h2> </header> ); }; <StyledHeaderComp title="A Unique Title" /> Example In this example, we will create styled components as the export hendercomp with header classname....

December 26, 2022 · 1 min · The Unknown Developer

How to add background image in styled components?

Solution To add a background image in styled components, you have to define a styled div element using the styled function from styled components, we will use a background image with css class and set-top left and set height: 200px and width: 200px. Snippet In this snippet, we will see add background image in styled components and use css style background : url (’logo192.png’). const StyledDiv = styled.div` background: url('logo192.png') no-repeat top left; background-size: contain; height: 200px; width: 200px; `; <StyledDiv className="App"> </StyledDiv> Example In this example, we will create styled componets library and uses it to define a new component called StyledDiv,as the background image set file logo192....

December 25, 2022 · 1 min · The Unknown Developer

How to get hours and minutes from date in React js?

Solution To get hours and minutes from date in React, you can use the getHours() and getMinutes() methods it will return hours and minutes from date. To format a date you can read my below article, here I have explained multiple ways to format a date. https://reactjssnippet.com/posts/how-to-display-date-in-react-js/ Snippet In this snippet, we will see a short example to get hours and minutes from date. const date = new Date(); const hours = date....

December 24, 2022 · 1 min · The Unknown Developer

How to get selected date from datepicker in React js?

Solution To get selected date from the date picker in React, you can use the onChange() attribute with the setState() method then you can easily get selected from datepicker. To format a date you can read my below article, here I have explained multiple ways to format a date. https://reactjssnippet.com/posts/how-to-display-date-in-react-js/ Snippet In this snippet, we will see a short example to get the value of the input type date ( datepicker )....

December 23, 2022 · 1 min · The Unknown Developer

How to disable previous date in input type date in React js?

Solution To disable previous date in input type date in React, you can use the min attribute you have to just pass your date in YYYY-MM-DD. Note: Your date should formated like this YYYY-MM-DD. To format a date you can read my below article, here I have explained multiple ways to format a date. https://reactjssnippet.com/posts/how-to-display-date-in-react-js/ Snippet In this snippet, we will see short example to disable previous date using min attribute....

December 22, 2022 · 1 min · The Unknown Developer

How to convert epoch time to date in React js?

Solution To convert epoch time to date in React, you can use the new Date() method which will return epoch time as a date object. To format a date you can read my below article, here I have explained multiple ways to format a date. https://reactjssnippet.com/posts/how-to-display-date-in-react-js/ Snippet In this snippet, we will take epoch time and use new Date() to convert in date. // Get epoch time const epochTime = 1609459200000; // This is Fri Jan 01 2021 in epoch time // convert epoch time to date const date = new Date(epochTime); console....

December 20, 2022 · 1 min · The Unknown Developer