This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<CascadingValue Value="_theme"> | |
<CascadingValue Value="@((Action)(() => _theme = (_theme == "light" ? "dark" : "light")))"> | |
<div> | |
<MyButton Text="Click me!"></MyButton> | |
<br /> | |
<ThemeToggler></ThemeToggler> | |
</div> | |
</CascadingValue> | |
</CascadingValue> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div title="switch theme" @onclick="Toggle" style="cursor: pointer;"> | |
@(Theme == "light" ? "🌙": "☀️") | |
</div> | |
@code { | |
[CascadingParameter] | |
public string Theme { get; set; } | |
[CascadingParameter] | |
public Action Toggle { get; set; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MyButton from './MyButton'; | |
import ThemeContext from './ThemeContext'; | |
import React, { useState } from 'react'; | |
import ThemeToggler from './ThemeToggler'; | |
function App() { | |
const [theme, setTheme] = useState('light'); | |
const value = { theme, setTheme }; | |
return ( | |
<ThemeContext.Provider value={value}> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useContext } from 'react'; | |
import ThemeContext from './ThemeContext'; | |
const ThemeToggler = () => { | |
const { theme, setTheme } = useContext(ThemeContext); | |
return ( | |
<div | |
style={{ cursor: 'pointer' }} | |
title="switch theme" | |
onClick={() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
const ThemeContext = React.createContext({ | |
theme: 'light', // current theme (default is light) | |
setTheme: () => {}, // function to change the theme (empty for now) | |
}); | |
export default ThemeContext; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach (var property in typeof(ListProductsRequest).GetProperties()) | |
{ | |
var name = property.Name.ToCamelCase(); | |
var getter = GenerateGetterLambda(property); | |
// Cache it | |
} |