投稿時間:2022-04-10 16:13:53 RSSフィード2022-04-10 16:00 分まとめ(14件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
js JavaScriptタグが付けられた新着投稿 - Qiita 【JavaScript】日付は `YYYY/MM/DD hh:mm:ss.iii` の形式で欲しい!のに無いから自作した https://qiita.com/yamazaki3104/items/ace05f204488ffb261f4 javascript 2022-04-10 15:30:08
Docker dockerタグが付けられた新着投稿 - Qiita 【Laravel Sail × Docker】Xdebugの止め方 https://qiita.com/sousai/items/8ccedc4dc697dac6f8df vscod 2022-04-10 15:20:20
Docker dockerタグが付けられた新着投稿 - Qiita Dockerコンテナを一般ユーザーで操作する https://qiita.com/RyoSakon001/items/e1c0197f0d7c881d3e70 docker 2022-04-10 15:10:10
Ruby Railsタグが付けられた新着投稿 - Qiita WindowsでのVagrantを用いたRails6環境構築 https://qiita.com/smasa1112/items/210193f891b61842b427 cloudaws 2022-04-10 15:41:04
海外TECH DEV Community React Cheat Sheet (with React 18) https://dev.to/ruppysuppy/react-cheat-sheet-with-react-18-4jl2 React Cheat Sheet with React Are you someone trying to dive into the world of React but keep forgetting how to do stuff amp hitting roadblocks Fret not my friend now you no longer need to stumble around in the dark This article is a memory aid for all things React focusing on Functional Components only Create a React AppThe complete guide to creating a React app is available here If you want to bootstrap something quickly create react app is the way to go Initialize a new appnpx create react app my app nameORyarn create react app my app name Run the app default port is cd my app namenpm startORyarn start Render a React Componentimport ReactDOM from react dom client import App from App const root ReactDOM createRoot document getElementById root root render lt App gt Functional Componentsconst Component gt return lt div gt Hello World lt div gt Pre requisites Must have an uppercase first letterMust return JSXSince React there is no need to import React from react Importing ComponentsComponents can be exported amp imported from other files thus promoting Code splitting and reusability Default Exportfunction Component gt lt div gt Hello World lt div gt export default Componentimport Component from Component function App gt lt Component gt Named Exportexport function Component gt lt div gt Hello World lt div gt import Component from Component function App gt lt Component gt Lazy Loadingfunction Component gt lt div gt Hello World lt div gt export default Componentimport lazy Suspense from react const Component lazy gt import Component function App gt lt Suspense fallback lt div gt Loading lt div gt gt lt Component gt lt Suspense gt JSX Rules Must return a single elementconst Component gt INVALID return lt div gt Hello lt div gt lt div gt World lt div gt return lt div gt Hello World lt div gt ORconst Component gt lt React Fragment gt can be replaced with just lt gt On wrapping the children with any element you can create as many levels of nesting as you want return lt React Fragment gt lt div gt Hello lt div gt lt div gt World lt div gt lt React Fragment gt Opening tags need to be closed can use self closing tags const Component gt INVALID return lt input gt return lt input gt Use React attributes instead of HTML attributesconst Component gt INVALID return lt div class foo gt Hello World lt div gt return lt div className foo gt Hello World lt div gt StylingTo use styling you do need to add css loader amp style loader to your webpack config js if you are manually building your React app Luckily create react app comes pre configured to enable styling CSS Imports app css redText color red import app css function App return lt h className redText gt Hello World lt h gt Inline CSSconst Component gt return lt div style color red gt Hello World lt div gt CSS Modules app css redText color red import classes from app css function App return lt h className classes redText gt Hello World lt h gt Embedding JavaScriptPre requisites Must be an expression with a return value can be JSX too Must be wrapped in curly braces const Component gt const isLoggedIn true return lt div gt isLoggedIn User is Authenticated lt LogIn gt lt div gt Component PropertiesThese are the values with which the component is initialized props are accepted as the function parameter no propsfunction App return lt Person name Mike age gt with propsconst Person props gt return lt h gt Name props name Age props age lt h gt with destructured propsconst Person name age gt return lt h gt Name name Age age lt h gt Childrenchildren is a special prop passed to a component that is rendered inside the component const Component children gt return lt div gt children lt div gt const App gt return lt Component gt lt h gt Hello World lt h gt lt Component gt Default Props JavaScript ish syntaxconst Component name Mike gt return lt div gt name lt div gt OR React ish syntaxconst Component name gt return lt div gt name lt div gt Component defaultProps name Mike Listsconst people id name Mike id name Peter id name John function App return people map person gt lt div key person id gt person name lt div gt The key is an optional prop available on all elements it is used internally by React to keep track of which elements have changed For lists it is highly recommended that you do add a key Prop DestructuringPerson is a component that accepts a name prop function App return people map id person gt lt Person key id person gt Eventsconst clickHandler gt alert Hello World function App return lt gt lt h gt Welcome to my app lt h gt lt button onClick clickHandler gt Say Hi lt button gt lt gt or inline function App return lt gt lt h gt Welcome to my app lt h gt lt button onClick gt alert Hello World gt Say Hi lt button gt lt gt We can also pass arguments to the handlerconst clickHandler message gt alert message function App return lt gt lt h gt Welcome to my app lt h gt lt button onClick gt clickHandler Hello World gt Say Hi lt button gt lt gt The events by default pass the event object as the first argument const clickHandler event gt console log event target function App return lt gt lt h gt Welcome to my app lt h gt lt button onClick clickHandler gt Say Hi lt button gt lt gt You can even pass on a handler from a parent and execute it inside the childfunction Todo item onDelete return lt div gt item lt button onClick gt onDelete item gt lt div gt function Todos const handleDelete todo gt const newTodos todos filter item gt item todo setTodos gt newTodos return todos map todo gt lt Todo item todo onDelete handleDelete gt HooksHooks are functions that let you “hook into React state and lifecycle features from function components Pre requisites Hook always starts with the use prefixMust be invoked only in a React functional componentMust be called only at the top level of a functional componentDeclaration CAN NOT be called conditionally useStateuseState is a hook that lets you manage the state in a functional component function App const count setCount useState return lt div gt lt p gt You clicked count times lt p gt lt button onClick gt setCount count gt Click me lt button gt lt div gt useEffectuseEffect is a hook that lets you access lifecycle methods in a functional component function App const count setCount useState useEffect gt console log Initialized clean up function runs before the component is unmounted return gt console log Cleaned up empty array run during mount only useEffect gt document title You clicked count times count array with count run everytime count changes return lt div gt lt button onClick gt setCount count gt Click me lt button gt lt div gt useContextuseContext is a hook that returns the data for the given context the state management tool that ships with React const ThemeContext createContext light function App return lt ThemeContext Provider value light gt lt Component gt lt ThemeContext Provider gt function Component const theme useContext ThemeContext returns light return lt div gt lt p gt The current theme is theme lt p gt lt div gt useReduceruseReducer is a hook that lets you manage state in functional components but unlike useState it uses the Redux patternfunction App const count dispatch useReducer state action gt switch action case increment return state case decrement return state default throw new Error return lt div gt lt p gt count lt p gt lt button onClick gt dispatch increment gt lt button gt lt button onClick gt dispatch decrement gt lt button gt lt div gt useCallbackThe useCallback hook returns a memoized version of the callback with the sole purpose of optimizing performance function App const count setCount useState const increment useCallback gt setCount c gt c return lt div gt lt p gt count lt p gt lt button onClick increment gt lt button gt lt div gt useMemoThe useMemo hook returns a memoized version of the value produced by the callback Just like useCallback useMemo is a performance optimization hook function App const count setCount useState const memoizedIncrement useMemo gt return gt setCount c gt c return lt div gt lt p gt count lt p gt lt button onClick memoizedIncrement gt lt button gt lt div gt useRefThe useRef hook returns a mutable ref object whose current property is initialized to the passed argument initialValue The returned object will persist for the full lifetime of the component unless manually changed function App const inputRef useRef null const onButtonClick gt inputRef current focus return lt div gt lt input ref inputRef type text gt lt button onClick onButtonClick gt Focus on the input lt button gt lt div gt useTransitionThe useTransition hook lets you mark less urgent actions as transitions function App const input setInput useState const data setData useState items const isPending startTransition useTransition useEffect gt input change is prioritized over filtering a long list startTransition gt setData items filter i gt i includes input input const updateInput e gt setInput e target value return lt div gt lt input value input onChange updateInput gt lt ul gt data map item gt lt li key item gt item lt li gt lt ul gt lt div gt useDeferredValueThe useDeferredValue hook lets you intentionally defer updating values so they don t slow down other parts of the pagefunction App const deferredValue useDeferredValue value return lt MyComponent value deferredValue gt That s all folks If you think I have missed something please add them in the comments Happy Developing Thanks for readingNeed a Top Rated Front End Development Freelancer to chop away your development woes Contact me on UpworkWant to see what I am working on Check out my Personal Website and GitHubWant to connect Reach out to me on LinkedInI am a freelancer who will start off as a Digital Nomad in mid Want to catch the journey Follow me on InstagramFollow my blogs for Weekly new Tidbits on DevFAQThese are a few commonly asked questions I get So I hope this FAQ section solves your issues I am a beginner how should I learn Front End Web Dev Look into the following articles Front End Development RoadmapFront End Project Ideas 2022-04-10 06:18:48
ニュース BBC News - Home Dwarfism: Woman's battle against ignorance starts in schools https://www.bbc.co.uk/news/uk-wales-61037196?at_medium=RSS&at_campaign=KARANGA frequent 2022-04-10 06:08:15
ニュース BBC News - Home Australian Grand Prix: Charles Leclerc wins in Melbourne as title rival Max Verstappen retires https://www.bbc.co.uk/sport/formula1/61056578?at_medium=RSS&at_campaign=KARANGA Australian Grand Prix Charles Leclerc wins in Melbourne as title rival Max Verstappen retiresCharles Leclerc takes a dominant victory in the Australian Grand Prix to move into a commanding position in the World Championship 2022-04-10 06:34:24
北海道 北海道新聞 世界遺産・青岸渡寺で開山祭 和歌山・那智勝浦 https://www.hokkaido-np.co.jp/article/667853/ 世界遺産 2022-04-10 15:33:00
北海道 北海道新聞 北海道内2145人感染 5日連続2千人台 新型コロナ https://www.hokkaido-np.co.jp/article/667849/ 北海道内 2022-04-10 15:29:44
北海道 北海道新聞 なでしこ候補、強化合宿打ち上げ 男子ユースに0―2で敗れる https://www.hokkaido-np.co.jp/article/667848/ 強化合宿 2022-04-10 15:23:00
北海道 北海道新聞 藤岡は敗れ王座統一ならず ボクシング女子世界戦 https://www.hokkaido-np.co.jp/article/667847/ 世界ボクシング協会 2022-04-10 15:23:00
北海道 北海道新聞 SL清掃しませんか? 室蘭「ミガキ隊」が隊員証発行 https://www.hokkaido-np.co.jp/article/667844/ 蒸気機関車 2022-04-10 15:08:00
北海道 北海道新聞 <市場発!>バナナ、キウイ 割安な輸入果実に灯った「黄信号」 https://www.hokkaido-np.co.jp/article/667112/ 黄信 2022-04-10 15:02:03
IT 週刊アスキー 創業65周年の大戸屋「デミグラスチキンかつ定食」を1ヵ月限定で復刻販売 https://weekly.ascii.jp/elem/000/004/088/4088794/ 限定 2022-04-10 15:30:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)