投稿時間:2021-06-14 02:14:05 RSSフィード2021-06-14 02:00 分まとめ(15件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) Vue.js propsのデフォルトに、dataプロパティの値やmethodsの関数を指定するには? https://teratail.com/questions/343865?rss=all Vuejspropsのデフォルトに、dataプロパティの値やmethodsの関数を指定するにはmethodsfconsolelogdeffunctestpropsfunctypeFunctiondefaultthisfこの記述できないっぽいんですがなんとかなりませんかdefaultに「thisxxx」を指定ってできないんでしょうかコンポーネントに関数の参照渡して子側で呼び出すことがしたいです。 2021-06-14 01:54:49
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) setInterval 2つの稼働を1つにする https://teratail.com/questions/343864?rss=all 2021-06-14 01:47:23
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) 編集画面にて小モデルの要素を削除する際にバリデーションを掛けたい https://teratail.com/questions/343863?rss=all kidsのstatusはdefaultでが入っていて、の場合削除できなくする。 2021-06-14 01:32:23
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) Jiraのエピックと課題タイプの使い方、区別はどう考えればよいのでしょうか https://teratail.com/questions/343862?rss=all Jiraのエピックと課題タイプの使い方、区別はどう考えればよいのでしょうかよろしくお願いいたします。 2021-06-14 01:21:05
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) 二分探索木が動作しない https://teratail.com/questions/343861?rss=all 2021-06-14 01:08:29
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) JavaScript JSON.parseのエラー探知/スキップ https://teratail.com/questions/343860?rss=all 2021-06-14 01:07:43
海外TECH DEV Community React Hooks https://dev.to/kpiteng/react-hooks-20kc React HooksHello Developers All of you know about functional components Today we will go to the next level in functional components and see in detail how React Hooks allow us to implement variables functions and managing states in functional components Top React Hooks useState useEffect useRef useMemo useCallback We will see each in detail and see how we develop a powerful React app by using Hooks React Hooks useStateuseEffectuseRefuseMemouseCallbackPlease download full source code from our GitHub useState ーuseState hooks allow you to create update state variables in functional components Here we will take two state variables with different data types Numeric String and Object and see how it will work const numVal setNumVal useState const strVal setStrVal useState KPITENG const objVal setObjValue useState num numVal str strVal You see it s very simple here we take the numVal Numeric state variable with initial value of Same way I have created strVal String state variable with initial value of KPITENG And objVal Object state variable with initial value num str KPITENG Now Let s see usage in functional components Let s create a TextInput component and assign numeric value from state lt View gt lt Text gt Enter Number lt Text gt lt TextInput keyboardType numeric placeholder Enter Number value String numVal See how we assign state value style Styles textInput gt lt View gt Same way here we created another TextInput and assigned string value from state lt View style Styles stringContainer gt lt Text gt Enter String lt Text gt lt TextInput placeholder Enter String value strVal See how we assign state value style Styles textInput gt lt View gt This seems good Till we have used the State variable Now let s try to update the state variable Let s add TextInput onChangeText event and update state Variable lt View style Styles stringContainer gt lt Text gt Enter String lt Text gt lt TextInput placeholder Enter String onChangeText text gt setStrVal text update strVal with use input text setObjValue objVal str text update str in objVal with user input text value strVal style Styles textInput gt lt View gt You see it s very simple to update the State variable Now if you want to see values which you have updated in State then let s read values from State and render in Text Component lt View style Styles container gt lt View gt lt Text gt Enter Number lt Text gt lt TextInput keyboardType numeric placeholder Enter Number onChangeText text gt setNumVal text setObjValue objVal num text value String numVal style Styles textInput gt lt Text style Styles stateValue gt Number numVal lt Text gt render here lt View gt lt View style Styles stringContainer gt lt Text gt Enter String lt Text gt lt TextInput placeholder Enter String onChangeText text gt setStrVal text setObjValue objVal str text value strVal style Styles textInput gt lt Text style Styles stateValue gt String strVal lt Text gt render here lt View gt lt View gt lt Text gt JSON stringify objVal lt Text gt render here lt View gt lt View gt useEffect ーuseEffect hooks allow developers to take action on a certain stage of component life cycle and event occured like First Time Render Component Update State Variable Props Update etc Let s see step by step useEffect gt console log useEffect with will call one time while component render numVal Here we have created useEffect hooks with empty braces which means it is called only when component load This is similar to componentDidMount integrationBut if you want to call useEffect when numVal state variable gets updated Then simply add numValue in useEffect useEffect gt console log useEffect with numValue will call every time while numVal changed numVal numVal This seems perfect But with this integration useEffect call with two reasons Initial Component Load and While any changes in state variable in numVal But I want to call useEffect only when numVal changed not on Component Load then import useIsMount from useIsMount const isMount useIsMount function UseEffectExample const numVal setNumVal useState const strVal setStrVal useState KPITENG const isMount useIsMount function UseEffectExample const numVal setNumVal useState const isMount useIsMount useEffect gt if isMount console log This console log on first time render but not on change on numVal else console log This console log every time when numVal changed but not first time numVal numVal return lt View style Styles container gt lt View gt lt Text gt Enter Number lt Text gt lt TextInput keyboardType numeric placeholder Enter Number onChangeText text gt setNumVal text value String numVal style Styles textInput gt lt Text style Styles stateValue gt Number numVal lt Text gt lt View gt lt View gt Here I have added another Hooks useIsMount which helps to identify that component loaded first time and it s called second time due to state variable changes So I have added the condition if isMount true which means component load first time If isMount false which means it s getting called due to state variable changes This is code for useIsMount hooks import useRef useEffect from react export const useIsMount gt const isMountRef useRef true useEffect gt isMountRef current false return isMountRef current useRef ーuseRef hooks returns a mutable ref object The value will persist for the full lifetime of the component Let s take one example and understand real time use of useRef We already have TextInput now what we will do we will add one Button TouchableOpacity on press of it we will focus TextInput so the user can directly type it Let s do code const stringInput useRef null lt TextInput ref stringInput onChangeText text gt setStrVal text value strVal placeholder Enter String gt lt TouchableOpacity onPress gt stringInput current focus gt lt Text gt Press To Focus Keyboard lt Text gt lt TouchableOpacity gt See full code integration for useReffunction UseRefExample const strVal setStrVal useState KPITENG const stringInput useRef null return lt View style Styles container gt lt View gt lt Text gt Enter Number lt Text gt lt TextInput ref stringInput assign value to ref useRef placeholder Enter String onChangeText text gt setStrVal text value strVal style Styles textInput gt lt Text style Styles stateValue gt String strVal lt Text gt lt View gt lt View style Styles accessNumberInputContainer gt lt TouchableOpacity onPress gt stringInput current focus used ref here to focus keyboard console log stringInput stringInput gt lt Text gt Press To Focus Keyboard lt Text gt lt TouchableOpacity gt lt View gt lt View gt export default UseRefExample useMemo ーuseMemo hooks helps developers to avoid re rendering of child components to improve the performance of react application Let s take an example const technology name React Native status true name React js status true name Next js status true const arrTechnology setArrTechnology useState technology return lt View style Styles container gt lt FlatList data arrTechnology keyExtractor item gt String item name renderItem item index gt lt UseMemoListItem item item gt ItemSeparatorComponent gt lt UseMemoListItemSeprator gt showsVerticalScrollIndicator false gt lt View gt Here We have created an array to render in FlatList Let s see Code of FlatListItemimport useMemo from react function UseMemoListItem item return lt View style Styles container gt lt View style Styles elementsContainer gt lt Text gt item name lt Text gt lt View gt lt View gt export default UseMemoListItem Seems all good you can see FlatList rendered Perfectly But What happens if you have Switch in FlatListItem onChange of it you want update status to true false in arrTechnology then Then It will re render all FlatListItems instead of updating rendering specific FlatListItem Which causes performance issues Think of having records then each time it will render FlatListItem Here useMemo helps use useMemo helps to avoid re rendering by memoizing the value of state variable props variable Let s see integrationfunction UseMemoListItem item onChange arrTechnology return useMemo gt return lt View style Styles container gt lt View style Styles elementsContainer gt lt Text gt item name lt Text gt lt Switch onValueChange onChange value item status gt lt View gt lt View gt lt Text gt JSON stringify arrTechnology lt Text gt lt View gt lt View gt item status export default UseMemoListItem Here We have wrapped render into useMemo and tell useMemo to re render components only when item status is changed after initial render Let s see full source code src UseMemoExample index jsimport as React from react import View FlatList from react native import useState from react import UseMemoListItem from UseMemoListItem import UseMemoListItemSeprator from UseMemoListItemSeprator import Styles from Styles const technology name React Native status true name React js status true name Next js status true function UseMemoExample const arrTechnology setArrTechnology useState technology const onChangeSwitch index gt let array arrTechnology let object array index object status object status array index object setArrTechnology array return lt View style Styles container gt lt FlatList data arrTechnology keyExtractor item gt String item name renderItem item index gt lt UseMemoListItem arrTechnology arrTechnology item item onChange gt onChangeSwitch index gt ItemSeparatorComponent gt lt UseMemoListItemSeprator gt showsVerticalScrollIndicator false gt lt View gt export default UseMemoExample useCallback ーuseCallback helps developers to memorize the action instead of creating separate functions on each render In the previous example we have used onChangeSwitch action What happens when component render it will render onChangeSwitch if you have more records in FlatList due to change component re render then each time onChangeSwitch instance gets created To avoid this creation I will use useCallback which will memoize the action import useState useCallback from react const onChangeSwitch useCallback index gt let array arrTechnology let object array index object status object status array index object setArrTechnology array You see we have only returned the useCallBack action which means this action will create only one time only Thanks for reading the article step by step now you have a detailed idea on how to create a state variable how to integrate Hooks into a functional component Please download full source code from our GitHub Thanks for reading Article KPITENG DIGITAL TRANSFORMATIONwww kpiteng com blogs hello kpiteng comConnect Follow Us On Linkedin Facebook Instagram 2021-06-13 16:23:31
海外TECH DEV Community JavaScript-30-Day-13 https://dev.to/cenacr007_harsh/javascript-30-day-13-337i JavaScript Day Slide in on ScrolldemoOn Day of JS we made a Slide in on Scroll that is when you slide down the image sort of slide themselves in form left or right The images are hidden by default using CSS slide in opacity transition all s align left slide in transform translateX scale align right slide in transform translateX scale Basically we have made their opacity to be and using translate slightly pushed them off the window We also do scale of to get a fade in effect During sliding in we add a active class to it which will make their opacity and scale them back to normal size slide in active opacity transform translateX scale So let s get right into the JavaScript First thing we need to do is select all the images that we are going to be listening for by using slide in class which we gave to all our images for example lt img src class align left slide in gt lt img src class align right slide in gt const sliderImages document querySelectorAll slide in Now we ll create a function called checkSlide that will run every time the person scrolls so we ll add an eventListener for the scroll event window addEventListener scroll debounce checkSlide Now you might be wondering what is this debounce thing we have wrapped around the checkSlide function Essentially the scroll event gets fired off hundreds of times in one scroll and this can cause a little bit of a performance issue We can check how many times the event gets fired off by using console count e function checkSlide e console count e So to avoid this performance issue we use a debouncer function What this function essentially does is that whatever function is supplied to it and whatever wait interval is set in it it makes sure that the passed function is run once every x seconds where x is the wait interval in millisecond function debounce func wait immediate true var timeout return function var context this args arguments var later function timeout null if immediate func apply context args var callNow immediate amp amp timeout clearTimeout timeout timeout setTimeout later wait if callNow func apply context args Here func is the checkSlide function we have passed here debounce checkSlide and wait is millisecond So the debouncer function runs every time but the checkSlide function runs once every ms now which can be verified using the console count Note It s always a good idea to decbounce scroll event Now inside the checkSlide function we ll do the math for when the Images should slide in and when should they slide out First of all we ll loop every single image and figure out when each image need to be shown What we want is while scrolling when we reach half of the image height on our window the image should slide in and when we have scrolled past the bottom of the image we ll slide it out so that we can have the same slide in effect when we scroll back up This calculates the distance in pixel of the image half way throughconst slideInAt window scrollY window innerHeight sliderImage height Here window scrollY gives how far we have scrolled down from the top of the browser window but it gives the distance only upto the the top of the viewport and we want to know the distance upto the bottom of our window so we add window innerHeight to it Now since we want the animation to happen when we are exactly halfway through the image so we subtract that much distance using sliderImage height Now slideInAt contains the exact pixel when the image should slide in Similarly we calculate when we reach the bottom of the image by usingconst imageBottom sliderImage offsetTop sliderImage height Where sliderImage offsetTop gives the distance in pixel between the top of he image and the top of the browser window and hence by adding sliderImage height we get the bottom of the image Now we need to determine things First is the image half shown which we do by const isHalfShown slideInAt gt sliderImage offsetTop Secondly if we have not scrolled past the image const isNotScrolledPast window scrollY lt imageBottom and only if both of them are true we add the active class to the slider images else we remove it if isHalfShown amp amp isNotScrolledPast sliderImage classList add active else sliderImage classList remove active Here is the complete JavaScript code function debounce func wait immediate true var timeout return function var context this args arguments var later function timeout null if immediate func apply context args var callNow immediate amp amp timeout clearTimeout timeout timeout setTimeout later wait if callNow func apply context args const sliderImages document querySelectorAll slide in function checkSlide e sliderImages forEach sliderImage gt halfway through the image const slideInAt window scrollY window innerHeight sliderImage height bottom of the iamge const imageBottom sliderImage offsetTop sliderImage height const isHalfShown slideInAt gt sliderImage offsetTop const isNotScrolledPast window scrollY lt imageBottom if isHalfShown amp amp isNotScrolledPast sliderImage classList add active else sliderImage classList remove active window addEventListener scroll debounce checkSlide and with this our project for the day was completed GitHub repo cenacrharsh JS DAY Blog on Day of javascript JavaScript Day KUMAR HARSH・Jun ・ min read javascript github webdev Blog on Day of javascript JavaScript Day KUMAR HARSH・Jun ・ min read javascript html webdev css Blog on Day of javascript JavaScript Day KUMAR HARSH・Jun ・ min read javascript html webdev github Follow me on TwitterFollow me on LinkedinDEV Profile ltag user id follow action button background color important color important border color important KUMAR HARSH B Tech CSE Competitive Programming Enthusiast Front End Web Developer Cloud Computing GCP Blogger You can also do the challenge at javascriptThanks wesbos WesBos to share this with us Please comment and let me know your views Thank You 2021-06-13 16:02:35
海外TECH CodeProject Latest Articles Corona SEIR Workbench https://www.codeproject.com/Articles/5287156/Corona-SEIR-Workbench Corona SEIR WorkbenchPandemic SEIR and SEIRV modelling software and infrastructure for the Corona SARS COV COVID disease with data from Johns Hopkins University CSSE Robert Koch Institute and vaccination data from Our World In Data 2021-06-13 16:51:00
海外科学 NYT > Science Where the Grass is Greener, Except When It’s ‘Nonfunctional Turf’ https://www.nytimes.com/2021/06/11/science/drought-las-vegas-grass-mars.html grass 2021-06-13 16:21:42
ニュース BBC News - Home Big step towards vaccinating world, says PM https://www.bbc.co.uk/news/uk-57461640 criticism 2021-06-13 16:05:33
ニュース BBC News - Home Euro 2020: England 1-0 Croatia - Raheem Sterling helps Three Lions begin with victory https://www.bbc.co.uk/sport/football/51197735 wembley 2021-06-13 16:53:09
ニュース BBC News - Home Queen meets Joe Biden at Windsor Castle https://www.bbc.co.uk/news/uk-57461257 afternoon 2021-06-13 16:47:23
ニュース BBC News - Home Covid-19: Hospital data key to 21 June lockdown end, says Raab https://www.bbc.co.uk/news/uk-57459373 admissions 2021-06-13 16:39:25
ニュース BBC News - Home Israel's Netanyahu poised to lose power to new government https://www.bbc.co.uk/news/world-middle-east-57396990 administration 2021-06-13 16:39:11

コメント

このブログの人気の投稿

投稿時間: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件)