Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Reactのいいなと思ったところ
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Natsuki
January 15, 2025
1k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Reactのいいなと思ったところ
クラスメソッドのReact事情大公開スペシャル#6
https://classmethod.connpass.com/event/339885/presentation/
Natsuki
January 15, 2025
More Decks by Natsuki
See All by Natsuki
PHPStanのエラーをprettyにしようとしている
natsukiengr
0
39
jsが型安全になったっていい
natsukiengr
0
220
PHPStanをチームに内緒で開発に取り入れる方法
natsukiengr
1
1.9k
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
371
20k
New Earth Scene 8
popppiees
4
2.7k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
280
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
870
sira's awesome portfolio website redesign presentation
elsirapls
0
460
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
590
Automating Front-end Workflow
addyosmani
1369
210k
Designing Powerful Visuals for Engaging Learning
tmiket
1
610
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
270
Site-Speed That Sticks
csswizardry
13
1.6k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
300
Transcript
Reactのいいなと思ったところ Natsuki
今日話すこと 普段の業務ではVueを使用していて、最近Reactも業務外で勉強し始めました 初心者の目線で「Reactのココいいな」と思った点を共有したいと思います 自己紹介 Natsuki 普段はLaravel + Vueで開発
宣伝 Reactを学ぶ上で、VSCodeの拡張機能を作ってみました。 Your Themes
demo https://github.com/natsuki-engr/your-themes/blob/a1ce518a99009fd5baf489e592958c3c35b5dfcf/img/demo.gif
本題 「Reactのいいなと思ったところ」
dangerouslySetInnerHtml タグを含んだ文字列をHTMLタグとしてレンダリングしたい場合の`setInnerHtml`と同じ XSS攻撃の危険性があるので、注意が必要 「危険なんだぞ」という強い警告を感じるところがいい vueだと v-html で同じ実装ができるが、罪悪感が無い const markup =
'<p>some raw html</p>'; return <div dangerouslySetInnerHTML={{__html: markup}} />; ` ` <script setup> const markup = '<p>some raw html</p>' </script>
一貫してJS 「JSを知っていれば大体書ける」 たとえばJSX
JSX JSXの構成はJSとタグなので、テンプレートのために必要な知識が少ない JSのパラダイム/設計を持ち込める if(items.length === 0) { return <p>empty...</p> }
function ItemList({ items: Item[] }) { return ( <ul> {items.map(item => ( <li key={item.id}>{item.name}</li> ))} </ul> ); }
レンダリングの更新が分かりやすい 基本的に、引数やステートが変わって再レンダリングされるときに 「全て再計算される」と思っておいて、 ・特定の再計算をスキップしたければ useMemo 配列から値の検索とか ・特定の処理をスキップしたければ useEffect APIの呼び出しとか `
` ` `
useEffect/useMemo の悪い例 不要な useEffect 不要な useMemo https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state ` ` function
Form() { const [firstName, setFirstName] = useState('Taylor'); const [lastName, setLastName] = useState('Swift'); const [fullName, setFullName] = useState(''); useEffect(() => { setFullName(firstName + ' ' + lastName); }, [firstName, lastName]); return /** ... */ } ` ` function Form() { const [firstName, setFirstName] = useState("Taylor"); const [lastName, setLastName] = useState("Swift"); const fullName = useMemo( () => firstName + " " + lastName, [firstName, lastName] ); return; /** ... */ } const fullName = firstName + " " + lastName
なぜ今日この話をしようと思ったか
参考 【React】誤解される useMemo と 誤用される useState ―― 「A の変更に反応して B
の値が変わる」と考え るべきでない https://qiita.com/honey32/items/58e56e407d4d87e294a4 【React】useEffect の標準動作は「依存配列の中身が変わると実行」ではない https://qiita.com/honey32/items/62edf5165aced7d0c4bf useState + useEffect -> 再レンダリング中に毎回計算 (重ければ useMemo) https://scrapbox.io/honey32/useState_+_useEffect_->_再レンダリング中に毎回計算_(重ければ_useMemo) props または state に基づいて state を更新する - そのエフェクトは不要かも https://ja.react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state