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
| function MyComponent() { | |
| const [alphabet, set] = useState('A'); | |
| const prevAlphabet = usePrevious(alphabet); | |
| useEffect(() => { | |
| if (alphabet === 'C' && prevAlphabet === 'B') { | |
| doSomething(); | |
| } | |
| }, [alphabet]); | |
| // .. |
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 { useEffect, useRef } from 'react'; | |
| function usePrevious(value) { | |
| const ref = useRef(); | |
| useEffect(() => { | |
| ref.current = value; | |
| }, [value]); | |
| return ref.current; |
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 { useState, useCallback, useRef } from 'react'; | |
| import { removeNonNumeric, parseNumWithMaxValue } from '@/utils/StringUtils'; | |
| interface Options { | |
| initialValue?: string; | |
| maxValue?: number; | |
| minValue?: number; | |
| maxLength?: number; | |
| minLength?: number; | |
| autoFix?: boolean; |
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'; | |
| import Helmet from 'react-helmet'; | |
| function My() { | |
| return ( | |
| <> | |
| <Helmet> | |
| <title>My page</title> | |
| <meta property="description" content="discover yourself" /> |
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
| #[derive(Debug)] | |
| struct Currency { | |
| currency_symbol: char, | |
| exchange_rate: i32 | |
| } | |
| impl Currency { | |
| fn to_won(&self, amount: i32) -> i32 { | |
| self.exchange_rate * amount | |
| } |
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
| impl Currency { | |
| fn to_won(&mut self, amount: i32) -> i32 { | |
| self.exchange_rate = 1200; | |
| self.exchange_rate * amount | |
| } | |
| } | |
| fn main() { | |
| let dollar: Currency = Currency { | |
| currency_symbol: '$', |
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
| fn main() { | |
| let reference_to_nothing = dangle(); | |
| } | |
| fn dangle() -> &String { | |
| let s = String::from("hello"); | |
| &s | |
| } |
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
| fn main() { | |
| let mut s = String::from("hello"); | |
| change(&mut s); | |
| } | |
| fn change(some_string: &mut String) { | |
| some_string.push_str(", world"); | |
| } |
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
| fn main() { | |
| let s = String::from("hello"); | |
| change(&s); | |
| } | |
| fn change(some_string: &String) { | |
| some_string.push_str(", world"); | |
| } |
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
| fn main() { | |
| let s1 = String::from("hello"); | |
| let len = calculate_length(&s1); | |
| println!("The length of '{}' is {}.", s1, len); | |
| } | |
| fn calculate_length(s: &String) -> usize { | |
| s.len() |