Javanoscript + React - Day 36
useInputControl
Implement a useInputControl hook that manages a controlled input value and tracks additional form input states like:
[Property : Tracks : When it becomes true : When it becomes false]
* Touched : If input has been focused then blurred : When the user blurs the input (focus -> blur) : Never resets automatically
* Dirty : If value has been changed before : When the user types something Never resets automatically : -
* Different : If value is different from the original : When the value is different from the initial : When the value is same as the initial
The handleX functions returned by the hook are meant to be called on the relevant event handlers of <input> in order for the hook to work as intended.
Arguments
- initialValue: string: The initial value of the input
Returns
The hook returns an object with the following properties:
- value: string: The current value of the input
- dirty: boolean: Whether the user has been modified at least once
- touched: boolean: Whether the input was focused and blurred
- different: boolean: Whether the value is different from the initial value
- handleChange: (event: React.ChangeEvent<HTMLInputElement>) => void: A function that updates the value of the input
- handleBlur: (event: React.FocusEvent<HTMLInputElement>) => void: A function that to be called when the input is blurred
- reset: () => void: A function to reset to the initial value as well as the value of all states
@danceswithcode
@alithecodeguy
#js #javanoscript #interview87
useInputControl
Implement a useInputControl hook that manages a controlled input value and tracks additional form input states like:
[Property : Tracks : When it becomes true : When it becomes false]
* Touched : If input has been focused then blurred : When the user blurs the input (focus -> blur) : Never resets automatically
* Dirty : If value has been changed before : When the user types something Never resets automatically : -
* Different : If value is different from the original : When the value is different from the initial : When the value is same as the initial
The handleX functions returned by the hook are meant to be called on the relevant event handlers of <input> in order for the hook to work as intended.
export default function Component() {
const nameInput = useInputControl('Oliver');
return (
<form>
<div>
<label htmlFor="name">Name</label>
<input
id="name"
value={nameInput.value}
onChange={nameInput.handleChange}
onBlur={nameInput.handleBlur}
/>
</div>
<p>Touched: {nameInput.touched.toString()}</p>
<p>Dirty: {nameInput.dirty.toString()}</p>
<p>Different: {nameInput.different.toString()}</p>
<button type="submit" disabled={!nameInput.different}>
Submit
</button>
<button type="button" onClick={nameInput.reset}>
Reset
</button>
<form>
);
}
Arguments
- initialValue: string: The initial value of the input
Returns
The hook returns an object with the following properties:
- value: string: The current value of the input
- dirty: boolean: Whether the user has been modified at least once
- touched: boolean: Whether the input was focused and blurred
- different: boolean: Whether the value is different from the initial value
- handleChange: (event: React.ChangeEvent<HTMLInputElement>) => void: A function that updates the value of the input
- handleBlur: (event: React.FocusEvent<HTMLInputElement>) => void: A function that to be called when the input is blurred
- reset: () => void: A function to reset to the initial value as well as the value of all states
@danceswithcode
@alithecodeguy
#js #javanoscript #interview87
Javanoscript + React - Day 37
useMediaQuery
Implement a useMediaQuery hook that subscribes and responds to media query changes (e.g. screen size, resolution, orientation, etc.).
Hint: The window.matchMedia API would be helpful.
Arguments
- query: string: The media query to match. It must be a valid CSS media query string
Returns
The hook returns a boolean value that indicates whether the media query is a match.
@danceswithcode
@alithecodeguy
#js #javanoscript #interview87
useMediaQuery
Implement a useMediaQuery hook that subscribes and responds to media query changes (e.g. screen size, resolution, orientation, etc.).
export default function Component() {
const isSmallDevice = useMediaQuery('only screen and (max-width: 768px)');
return <div>{isSmallDevice && <a href="#">Menu</a>}</div>;
}
Hint: The window.matchMedia API would be helpful.
Arguments
- query: string: The media query to match. It must be a valid CSS media query string
Returns
The hook returns a boolean value that indicates whether the media query is a match.
@danceswithcode
@alithecodeguy
#js #javanoscript #interview87
توی این شرایط تخیلی اینترنت ، یه نفر توی تهران از طریق جایی به اسم ایدهپردازاران الکترونیک جوانان ، نود بیتکوین داره.
Sun Jan 25 , 12:39
Sun Jan 25 , 12:39
رقصنده با کد
توی این شرایط تخیلی اینترنت ، یه نفر توی تهران از طریق جایی به اسم ایدهپردازاران الکترونیک جوانان ، نود بیتکوین داره. Sun Jan 25 , 12:39
اطلاعات شرکت ایدهپردازان الکترونیک جوانان
رقصنده با کد
Photo
این هم صحبتهای آقای خسروی
داره در مورد کارآفرینی حرف میزنه
میگه بازداشت شده بودم ، توی ایران کار میکنی خودش خلافه.
میگه این تفکر وجود نداره که کارآفرین داره به کشور خدمت میکنه
https://www.instagram.com/reels/DOs_I7kDeQP/
اینجا هم در مورد پدر پولدار پدر فقیر صحبت میکنه
https://www.instagram.com/reels/DJMyAD4CFOw/
داره در مورد کارآفرینی حرف میزنه
میگه بازداشت شده بودم ، توی ایران کار میکنی خودش خلافه.
میگه این تفکر وجود نداره که کارآفرین داره به کشور خدمت میکنه
https://www.instagram.com/reels/DOs_I7kDeQP/
اینجا هم در مورد پدر پولدار پدر فقیر صحبت میکنه
https://www.instagram.com/reels/DJMyAD4CFOw/
استفاده از کلمه "درونگرا" به عنوان کلمهای با بار منفی یا بیماری ، بسیار ساده لوحانه هستش. ولی میشه حق داد که برونگراها ، این طرز تفکر رو رواج بدن.
فرض کن شما دهنت همیشه بازه و هیچ کار خاصی هم توی زندگیت نکردی و میبینی اکثریت جامعه هم مثل خودتن ولی اون دوست آرومت که سرش رو مینداخت پایین میرفت میومد ، بسیار جلوتر از تو داره پیش میره. حجم فشاری که به برونگراها میاره ، وحشتناکه.
خلاصه اگر آدم آرومی هستی و برونگرای مریض اطرافت میچرخه ، خیلی به خودت سخت نگیر. کار درست رو تو داری انجام میدی و اون شخص جز سروصدای اضافه، کاری از دستش برنمیاد.
پاورقی: البته همه درونگراها آدم درستی نیستن. همونطور که همه برونگراها آدمای بدی نیستن.
فرض کن شما دهنت همیشه بازه و هیچ کار خاصی هم توی زندگیت نکردی و میبینی اکثریت جامعه هم مثل خودتن ولی اون دوست آرومت که سرش رو مینداخت پایین میرفت میومد ، بسیار جلوتر از تو داره پیش میره. حجم فشاری که به برونگراها میاره ، وحشتناکه.
خلاصه اگر آدم آرومی هستی و برونگرای مریض اطرافت میچرخه ، خیلی به خودت سخت نگیر. کار درست رو تو داری انجام میدی و اون شخص جز سروصدای اضافه، کاری از دستش برنمیاد.
پاورقی: البته همه درونگراها آدم درستی نیستن. همونطور که همه برونگراها آدمای بدی نیستن.