-
Learn With Jason - Let's Learn SolidJS
-
Creating a Signal from Scratch
-
official tutorial
-
props/default props
- ์์ ์ปดํฌ๋ํธ์๊ฒ props๋ฅผ ๋๊ฒจ์ฃผ๋ ๋ฐฉ๋ฒ์ ์๊ฐํ๋ค
- ์๊ทธ๋์ props๋ก ๋๊ฒจ์ค ๋ ์๊ทธ๋์ ํธ์ถํ ๊ฒฐ๊ณผ๊ฐ์ ๋๊ฒจ์ฃผ๋ฉด ๋ฐ์์ฑ์ ์ถ์ ํ ์ ์๋ค
- props์ ๋ํดํธ๊ฐ ์ค์ ์ mergeProps๋ผ๋ ํจ์์์ ์ค์ ํ ์ ์๋ค
- mergeProps๋ ๊ฐ์ด ์์ผ๋ฉด ๊ฐ์ ๋ง๋๋ ํจ์์ ๋ถ๊ณผ. ๊ตณ์ด mergeProps ํจ์๊ฐ ํ์ํ์ง ์์.
-
split props
- solid.js๋ ์๊ทธ๋์ destructuringํ๋ ๋ฌธ๋ฒ์ด ํ์ฉ๋์ง ์์
- ๋์คํธ๋ญ์ฒ๋ง ํ์์์ ๋ฐ์์ฑ์ ์ถ์ ํ ์ ์์. ์์ ํ ์๋ก์ด ๊ฐ์ด ์์ฑ๋๊ธฐ ๋๋ฌธ
- ๊ทธ๋์ ๋์คํธ๋ญ์ฒ๋ง ๋ฌธ๋ฒ์ ๋์ ํ์ฌ splitProps๋ฅผ ์ฌ์ฉํด์ผ ํจ
- splitProps๋ฅผ ์ฌ์ฉํ๋ฉด ์ฌ๋ฌ๊ฐ์ ๊ฐ์ ํ๋์ ๋ณ์๋ก ๋ฌถ์ ์ ์์
- ๊ตํ : solid.js๋ ๋์คํธ๋ญ์ฒ๋ง์ ํ์ง ๋ชปํ๋ฏ๋ก ํํ๋ ฅ์ด ๋ง์ด ์ค์ด๋ฆ
-
lifecycle
-
onmount
- react.js์ useEffect๋ ๋ผ์ดํ์ฌ์ดํด๊ณผ effect๋ฅผ ๋ชจ๋ ์ํํ๋๋ก ๋์์ธ๋์์. ์ด๊ฒ์ ์ฌ์ฉ๋ฒ์ ํผ๋์ ์ผ๊ธฐํ ์ ์์
- solid๋ createEffect์ onMount๋ฅผ ๋ถ๋ฆฌํ์์. ๋งค์ฐ ์ํ ๊ฒฐ์ ์ด๋ผ๊ณ ์๊ฐํจ
- onMount๊ฐ ์กด์ฌํ๋ onUnmount๋ ์กด์ฌํ ๊ฑฐ๋ผ๋ ์ ์ถ๊ฐ ๊ฐ๋ฅํจ
- onMount๋ ์ฃผ๋ก fetch๋ localStorage๋ฑ์ ์ดํํธ๋ฅผ ์ํํ ๋ ์ฌ์ฉ๋จ. ๊ณต์ ์์ ์์๋ fetch๋ฅผ ์ํํจ
- ๊ฐ์ฅ ๋ณดํธ์ ์ธ onMount์ ํจํด : fetch์ดํ setSignal
-
oncleanup
- cleanup is not run on perspective of components
- run when that scope is triggered to re-evaluate
- for example, createEffect is re-evaluate when signal changes
- also oncleanup is used in useMemo that can be re-evaluated
-
-
event
-
style
- you can use either class or classList
- classList can avoid using tenerary operator
- ryansolid dislike tenerary operator
-
use directive
- ์ :
<div class="modal" use:clickOutside={setShow(false)}>
Some Modal
</div>- ์์ ์์ ์์ clickOutside ํจ์๋ `div.modal` ์๋ฆฌ๋จผํธ๋ฅผ ์ธ์๋ก ๋ฐ์ ์ ์๊ฒ๋๋ค
- ref์ use directive๋ ๋น์ทํ์ง๋ง ๋ฏธ๋ฌํ๊ฒ ๋ค๋ฅด๋ค
- `<input ref={some_variable} />` ๋ก ์์ฑํ๋ฉด some_variable์ input element๊ฐ ํ ๋น๋๋ค
- ํ์ง๋ง `<input use:some_function={() => { some_logic_here }} />` <- ์ด์ฒ๋ผ use directive์ some_function ํจ์๋ฅผ ํ ๋นํ๋ฉด some_function ํจ์์ ์ฒซ๋ฒ์งธ ์ธ์๋ก input element๋ฅผ ๋ฐ๋๋ค
- ์ฆ ref์ use directive ๋ชจ๋ html element๋ฅผ ์ฐธ์กฐํ๋ ๊ฒ์ ๊ฐ๋ค. ๊ทธ๊ฒ์ ๋ณ์๋ก ์ฐธ์กฐํ ์ง ํจ์์ ์ธ์๋ก ์ฐธ์กฐํ ์ง์ ์ฐจ์ด์ผ๋ฟ
- use directive๋ฅผ ์ฌ์ฉํ๋ฉด html element๋ฅผ ํจ์ ๋จ์๋ก ํ๋ก์ธ์ฑํ ์ ์์ผ๋ฏ๋ก ref๋ณด๋ค ๋ ์ ์ ํด ๋ณด์. ref๋ ์กฐ๊ธ ์ง์ ๋ถํ๊ณ use directive๋ ๊น๋ํ ๋๋