Тёмный
No video :(

CSS Custom Properties that Dynamically Update with React & JavaScript 

Colby Fayock
Подписаться 28 тыс.
Просмотров 17 тыс.
50% 1

Опубликовано:

 

28 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 35   
@colbyfayock
@colbyfayock 29 дней назад
Learn how to build a full stack Next.js app in my upcoming course: colbyfayock.com/course
@erinkahn4228
@erinkahn4228 2 года назад
I'm so glad I found your videos! You're a great teacher.
@colbyfayock
@colbyfayock 2 года назад
Thanks Erin! 🙌 Happy it helped
@harishsivaramakrishnan6999
@harishsivaramakrishnan6999 2 года назад
Awesome one dude! But please turn on Word-wrap in your VScode , that'll make it even more easy for us to look at the code Shortcut (Alt + Z)
@colbyfayock
@colbyfayock 2 года назад
Hey thanks. I'm a bit torn on that one. I feel like sometimes it makes it confusing to read as code blocks but I'll think on it now. Thanks for the feedback though either way
@Devil2Knight
@Devil2Knight Год назад
I watched this video and I subscribed. Great content, keep it up.
@colbyfayock
@colbyfayock Год назад
Awesome thanks 🙌
@colbyfayock
@colbyfayock Год назад
Get fresh tutorials and other free content straight to your inbox! colbyfayock.com/news
@DontFollowZim
@DontFollowZim 2 года назад
I prefer not to do direct DOM manipulation with libraries like Vue or React if possible, so for something like this, instead of setting the style on the `documentElement`, I would put it right in the template/JSX as a style attribute on one of the elements: `...` This, of course, requires a `useState` variable to hold the values and also requires you to have an appropriate element to put the styles on, so if the controlling component doesn't have access to the element that is getting controlled, then you'll need some type of global state.
@colbyfayock
@colbyfayock 2 года назад
great option!
@piero.guerrero
@piero.guerrero Год назад
In React that is going to raise an error. This the solution to complement your suggestion: function Component() { const myCustomStyle = { "--my-css-var": 10 } as React.CSSProperties; return {...} }
@marlonmorales6441
@marlonmorales6441 2 года назад
Amazing, great job with this tutorial, it help me a lot
@colbyfayock
@colbyfayock 2 года назад
Thank you 😁 glad to hear that!
@keenanreed5341
@keenanreed5341 2 года назад
Thanks, you're a lifesaver!
@colbyfayock
@colbyfayock 2 года назад
You got it 💪
@Dan-codes
@Dan-codes 2 года назад
Perfect videos, thank you.
@colbyfayock
@colbyfayock 2 года назад
np, glad you found it helpful!
@QtheCoder
@QtheCoder 2 года назад
To take this 1 step further, how would we implement this to a database for users? Basically, a user with a admin page can customer a look of something/thier page.
@colbyfayock
@colbyfayock 2 года назад
hey! you would likely want to store the "theme" ID within the database and use that ID to add the scope to the DOM found this that might help css-tricks.com/a-dry-approach-to-color-themes-in-css/
@VitorHugo-np9qs
@VitorHugo-np9qs Год назад
How can i export these value to set global color palletes?
@user-oy4kf5wr8l
@user-oy4kf5wr8l 2 года назад
Great video, thx buddy
@colbyfayock
@colbyfayock 2 года назад
np!
@anhtuanle4991
@anhtuanle4991 Год назад
Tks so much. but it to down perfomance in app ?
@colbyfayock
@colbyfayock Год назад
i think it depends on how you use it just like anything else. CSS is a powerful mechanism for controlling styles on a website, but you should use it with care and make sure that the JavaScript mechanisms you're using don't run out of control for most standard use cases i wouldn't expect it to have any issues
@tuyenkhong5415
@tuyenkhong5415 2 года назад
Whats the benefit of this over using state and directly modify React Element ? Wouldnt this be a bad practice as it directly modifies the DOM, which violates the principle of React.
@colbyfayock
@colbyfayock 2 года назад
i think it really depends on your use case and what you're trying to do. there's definitely a preferred flow for working with react but there's a reason why they provide the APIs to access the DOM natively. being able to programmatically work with CSS Custom Properties is a good instance of that. State might dictate the results of that, such as using a useEffect to update a custom property value based on state, but afaik there is no native custom property API for react
@dailymeow3283
@dailymeow3283 2 года назад
Hey Colby, can i add animation in the :root{} and keyframes to a css variable ?
@colbyfayock
@colbyfayock 2 года назад
i dont think you can assign @keyframes to a variable, but you likely could assign the name of the animation to a variable. similar to 12:04
@dizzland
@dizzland 2 года назад
just Awesome
@colbyfayock
@colbyfayock 2 года назад
🙌
@thezouchcoop
@thezouchcoop 2 года назад
postfix? 11:36
@colbyfayock
@colbyfayock 2 года назад
the `vmin` in this instance!
@thezouchcoop
@thezouchcoop 2 года назад
@@colbyfayock well I say this because it’s a suffix
@thezouchcoop
@thezouchcoop 2 года назад
@@colbyfayock I was just being a jerk I’m sorry 😭
@colbyfayock
@colbyfayock 2 года назад
​@@thezouchcoop 😂😂😂😂 well thanks for the correction, i'll be honest I was never great at some of the vocabulary of grammatical things, thought it was close though... funny enough looking for it on Google, the wikipedia for Postfix (Linguistics) redirects to Suffix en.wikipedia.org/wiki/Postfix_(linguistics) at least you knew what i meant! haha
Далее
Using CSS custom properties like this is a waste
16:12
Просмотров 168 тыс.
Секрет фокусника! #shorts
00:15
Просмотров 43 млн
C’est qui le plus fort 😂
00:18
Просмотров 11 млн
7 ways to deal with CSS
6:23
Просмотров 1,1 млн
CSS Tips And Tricks I Wish I Knew Before
12:12
Просмотров 470 тыс.
The problems with viewport units
13:23
Просмотров 360 тыс.
CSS Variables - manipulating them with JavaScript
11:22
Best Way to Add Popup Modals in React
26:19
Просмотров 7 тыс.
A deep dive into CSS color-mix()
18:06
Просмотров 27 тыс.
10 React Antipatterns to Avoid - Code This, Not That!
8:55
Every React Concept Explained in 12 Minutes
11:53
Просмотров 584 тыс.
Top 10 CSS One Liners That Will Blow Your Mind
13:34
Просмотров 945 тыс.
Секрет фокусника! #shorts
00:15
Просмотров 43 млн