Best JavaScript code snippet using qawolf
data.js
Source:data.js
1export const questions = [2 {3 question: 'ÐÑбеÑи ÑвеÑ',4 type: 'withImage',5 options: [6 {7 image: '/color/black.jpg',8 id: 0,9 points: {10 useState: 10,11 useReducer: 5,12 useCallback: 3,13 useImperativeHandle: 6,14 useEffect: 5,15 useRef: 7,16 useLayoutEffect: 317 }18 },19 {20 image: '/color/blue.jpg',21 id: 1,22 points: {23 useState: 4,24 useReducer: 10,25 useCallback: 3,26 useImperativeHandle: 5,27 useEffect: 4,28 useRef: 4,29 useLayoutEffect: 330 }31 },32 {33 image: '/color/gray.jpg',34 id: 2,35 points: {36 useState: 3,37 useReducer: 4,38 useCallback: 10,39 useImperativeHandle: 4,40 useEffect: 3,41 useRef: 5,42 useLayoutEffect: 443 }44 },45 {46 image: '/color/green.jpg',47 id: 3,48 points: {49 useState: 3,50 useReducer: 1,51 useCallback: 5,52 useImperativeHandle: 10,53 useEffect: 3,54 useRef: 5,55 useLayoutEffect: 156 }57 },58 {59 image: '/color/orange.jpg',60 id: 4,61 points: {62 useState: 1,63 useReducer: 8,64 useCallback: 3,65 useImperativeHandle: 5,66 useEffect: 10,67 useRef: 1,68 useLayoutEffect: 769 }70 },71 {72 image: '/color/pink.jpg',73 id: 5,74 points: {75 useState: 3,76 useReducer: 4,77 useCallback: 3,78 useImperativeHandle: 9,79 useEffect: 6,80 useRef: 10,81 useLayoutEffect: 482 }83 },84 {85 image: '/color/purple.jpg',86 id: 6,87 points: {88 useState: 1,89 useReducer: 6,90 useCallback: 5,91 useImperativeHandle: 2,92 useEffect: 5,93 useRef: 5,94 useLayoutEffect: 1095 }96 },97 {98 image: '/color/red.jpg',99 id: 7,100 points: {101 useState: 8,102 useReducer: 5,103 useCallback: 1,104 useImperativeHandle: 3,105 useEffect: 9,106 useRef: 8,107 useLayoutEffect: 7108 }109 },110 {111 image: '/color/yellow.jpg',112 id: 8,113 points: {114 useState: 3,115 useReducer: 9,116 useCallback: 5,117 useImperativeHandle: 3,118 useEffect: 1,119 useRef: 1,120 useLayoutEffect: 4121 }122 }123 ]124 },125 {126 question: 'ÐÑбеÑи ÑилÑм',127 type: 'withImage',128 options: [129 {130 image: '/movie/brother.png',131 text: '"ÐÑаÑ"',132 id: 0,133 points: {134 useState: 10,135 useReducer: 5,136 useCallback: 2,137 useImperativeHandle: 6,138 useEffect: 6,139 useRef: 7,140 useLayoutEffect: 3141 }142 },143 {144 image: '/movie/zhmurki.png',145 text: '"ÐмÑÑки"',146 id: 1,147 points: {148 useState: 4,149 useReducer: 10,150 useCallback: 5,151 useImperativeHandle: 5,152 useEffect: 4,153 useRef: 4,154 useLayoutEffect: 3155 }156 },157 {158 image: '/movie/indiana.png',159 text: '"Ðндиана ÐÐ¶Ð¾Ð½Ñ Ð¸ поÑледний кÑеÑÑовÑй поÑ
од"',160 id: 2,161 points: {162 useState: 5,163 useReducer: 4,164 useCallback: 10,165 useImperativeHandle: 4,166 useEffect: 3,167 useRef: 4,168 useLayoutEffect: 4169 }170 },171 {172 image: '/movie/godfather.png',173 text: '"ÐÑеÑÑнÑй оÑеÑ"',174 id: 3,175 points: {176 useState: 3,177 useReducer: 1,178 useCallback: 8,179 useImperativeHandle: 10,180 useEffect: 3,181 useRef: 6,182 useLayoutEffect: 1183 }184 },185 {186 image: '/movie/beauty.png',187 text: '"ÐÑаÑоÑка"',188 id: 4,189 points: {190 useState: 1,191 useReducer: 7,192 useCallback: 3,193 useImperativeHandle: 5,194 useEffect: 10,195 useRef: 8,196 useLayoutEffect: 7197 }198 },199 {200 image: '/movie/avengers.png',201 text: '"ÐÑÑиÑели: Ñинал"',202 id: 5,203 points: {204 useState: 3,205 useReducer: 4,206 useCallback: 7,207 useImperativeHandle: 9,208 useEffect: 6,209 useRef: 10,210 useLayoutEffect: 3211 }212 },213 {214 image: '/movie/revenant.png',215 text: '"ÐÑживÑий"',216 id: 6,217 points: {218 useState: 1,219 useReducer: 6,220 useCallback: 5,221 useImperativeHandle: 2,222 useEffect: 5,223 useRef: 5,224 useLayoutEffect: 10225 }226 },227 {228 image: '/movie/nocountry.png',229 text: '"СÑаÑикам здеÑÑ Ð½Ðµ меÑÑо"',230 id: 7,231 points: {232 useState: 8,233 useReducer: 5,234 useCallback: 6,235 useImperativeHandle: 9,236 useEffect: 7,237 useRef: 8,238 useLayoutEffect: 7239 }240 },241 {242 image: '/movie/animals.png',243 text: '"Ð¢Ð°Ð¹Ð½Ð°Ñ Ð¶Ð¸Ð·Ð½Ñ Ð´Ð¾Ð¼Ð°ÑниÑ
живоÑнÑÑ
2"',244 id: 8,245 points: {246 useState: 3,247 useReducer: 3,248 useCallback: 5,249 useImperativeHandle: 3,250 useEffect: 8,251 useRef: 7,252 useLayoutEffect: 4253 }254 }255 ]256 },257 {258 question: 'ÐÑбеÑи пеÑнÑ',259 type: 'withImage',260 options: [261 {262 image: '/song/despacito.png',263 text: 'Luis Fonsi: "Despacito"',264 id: 0,265 points: {266 useState: 6,267 useReducer: 5,268 useCallback: 6,269 useImperativeHandle: 6,270 useEffect: 5,271 useRef: 7,272 useLayoutEffect: 10273 }274 },275 {276 image: '/song/adele.png',277 text: 'Adele: "Rolling in the deep"',278 id: 1,279 points: {280 useState: 4,281 useReducer: 4,282 useCallback: 6,283 useImperativeHandle: 5,284 useEffect: 5,285 useRef: 10,286 useLayoutEffect: 3287 }288 },289 {290 image: '/song/beegees.png',291 text: 'Bee Gees: "How deep is your love"',292 id: 2,293 points: {294 useState: 5,295 useReducer: 4,296 useCallback: 7,297 useImperativeHandle: 4,298 useEffect: 10,299 useRef: 6,300 useLayoutEffect: 4301 }302 },303 {304 image: '/song/hellsbells.png',305 text: 'AC/DC: "Hells bells"',306 id: 3,307 points: {308 useState: 3,309 useReducer: 1,310 useCallback: 8,311 useImperativeHandle: 10,312 useEffect: 3,313 useRef: 5,314 useLayoutEffect: 1315 }316 },317 {318 image: '/song/survivor.png',319 text: 'Survivor: "Eye of the tiger"',320 id: 4,321 points: {322 useState: 1,323 useReducer: 5,324 useCallback: 10,325 useImperativeHandle: 5,326 useEffect: 2,327 useRef: 1,328 useLayoutEffect: 7329 }330 },331 {332 image: '/song/gaye.png',333 text: 'Marvin Gaye: "Lets get it on"',334 id: 5,335 points: {336 useState: 3,337 useReducer: 10,338 useCallback: 7,339 useImperativeHandle: 6,340 useEffect: 6,341 useRef: 1,342 useLayoutEffect: 6343 }344 },345 {346 image: '/song/pharell.png',347 text: 'Pharell Williams: "Happy"',348 id: 6,349 points: {350 useState: 10,351 useReducer: 6,352 useCallback: 5,353 useImperativeHandle: 2,354 useEffect: 5,355 useRef: 5,356 useLayoutEffect: 1357 }358 },359 {360 image: '/song/shortpairs.png',361 text: 'Shortparis: "СÑÑаÑно"',362 id: 7,363 points: {364 useState: 8,365 useReducer: 5,366 useCallback: 1,367 useImperativeHandle: 3,368 useEffect: 9,369 useRef: 8,370 useLayoutEffect: 7371 }372 },373 {374 image: '/song/arctic.png',375 text: 'Arctic Monkeys: "Four out of five"',376 id: 8,377 points: {378 useState: 3,379 useReducer: 9,380 useCallback: 5,381 useImperativeHandle: 3,382 useEffect: 1,383 useRef: 1,384 useLayoutEffect: 4385 }386 }387 ]388 },389 {390 question: 'Ðде ÑÑ Ð² пÑÑниÑÑ Ð²ÐµÑеÑом?',391 type: 'text',392 options: [393 {394 text: 'Со Ñвоей вÑоÑой половинкой',395 id: 2,396 points: {397 useState: 5,398 useReducer: 4,399 useCallback: 10,400 useImperativeHandle: 4,401 useEffect: 3,402 useRef: 4,403 useLayoutEffect: 4404 }405 },406 {407 text: 'ÐÑÑ
Ð°Ñ Ñ Ð´ÑÑзÑÑми',408 id: 3,409 points: {410 useState: 3,411 useReducer: 1,412 useCallback: 5,413 useImperativeHandle: 10,414 useEffect: 3,415 useRef: 4,416 useLayoutEffect: 1417 }418 },419 {420 text: 'Ðа Ñвиданке',421 id: 0,422 points: {423 useState: 10,424 useReducer: 5,425 useCallback: 8,426 useImperativeHandle: 6,427 useEffect: 7,428 useRef: 7,429 useLayoutEffect: 3430 }431 },432 {433 text: 'СплÑ',434 id: 4,435 points: {436 useState: 1,437 useReducer: 8,438 useCallback: 5,439 useImperativeHandle: 5,440 useEffect: 10,441 useRef: 1,442 useLayoutEffect: 7443 }444 },445 {446 text: 'ТÑÑÑÑÑÑ Ð² клÑбе',447 id: 5,448 points: {449 useState: 3,450 useReducer: 4,451 useCallback: 7,452 useImperativeHandle: 9,453 useEffect: 6,454 useRef: 10,455 useLayoutEffect: 8456 }457 },458 {459 text: 'СмоÑÑÑ ÐºÐ¸Ð½Ð¾ дома',460 id: 6,461 points: {462 useState: 1,463 useReducer: 6,464 useCallback: 5,465 useImperativeHandle: 2,466 useEffect: 5,467 useRef: 5,468 useLayoutEffect: 10469 }470 },471 {472 text: 'ÐÑÐ¼Ð°Ñ Ð¾ бÑвÑей',473 id: 1,474 points: {475 useState: 4,476 useReducer: 10,477 useCallback: 1,478 useImperativeHandle: 5,479 useEffect: 5,480 useRef: 4,481 useLayoutEffect: 3482 }483 },484 {485 text: 'ÐгÑÐ°Ñ Ð² наÑÑолки',486 id: 7,487 points: {488 useState: 8,489 useReducer: 5,490 useCallback: 1,491 useImperativeHandle: 3,492 useEffect: 9,493 useRef: 8,494 useLayoutEffect: 7495 }496 }497 ]498 },499 {500 question: 'ÐÑбеÑи ÑÑпеÑÑпоÑобноÑÑÑ',501 type: 'text',502 options: [503 {504 text: 'ÐевидимоÑÑÑ',505 id: 0,506 points: {507 useState: 10,508 useReducer: 5,509 useCallback: 8,510 useImperativeHandle: 6,511 useEffect: 7,512 useRef: 7,513 useLayoutEffect: 3514 }515 },516 {517 text: 'ÐÑÑеÑеÑÑвие во вÑемени',518 id: 1,519 points: {520 useState: 4,521 useReducer: 10,522 useCallback: 6,523 useImperativeHandle: 5,524 useEffect: 3,525 useRef: 4,526 useLayoutEffect: 3527 }528 },529 {530 text: 'ÐиÑаÑÑ Ð¿Ð¾Ð¿ÑлÑÑнÑе ÑвиÑÑ',531 id: 2,532 points: {533 useState: 4,534 useReducer: 4,535 useCallback: 10,536 useImperativeHandle: 4,537 useEffect: 3,538 useRef: 5,539 useLayoutEffect: 4540 }541 },542 {543 text: 'СÑпеÑÑила',544 id: 3,545 points: {546 useState: 3,547 useReducer: 1,548 useCallback: 8,549 useImperativeHandle: 10,550 useEffect: 3,551 useRef: 4,552 useLayoutEffect: 1553 }554 },555 {556 text: 'СÑпеÑÑолеÑаÑноÑÑÑ',557 id: 4,558 points: {559 useState: 1,560 useReducer: 3,561 useCallback: 4,562 useImperativeHandle: 5,563 useEffect: 10,564 useRef: 1,565 useLayoutEffect: 7566 }567 },568 {569 text: 'ТелепоÑÑаÑиÑ',570 id: 5,571 points: {572 useState: 3,573 useReducer: 4,574 useCallback: 7,575 useImperativeHandle: 3,576 useEffect: 6,577 useRef: 10,578 useLayoutEffect: 4579 }580 },581 {582 text: 'ЧиÑаÑÑ Ð¼ÑÑли',583 id: 6,584 points: {585 useState: 1,586 useReducer: 6,587 useCallback: 5,588 useImperativeHandle: 2,589 useEffect: 5,590 useRef: 5,591 useLayoutEffect: 10592 }593 },594 {595 text: 'ÐÑÑаÑÑ Ð¿Ð¾Ð´ водой',596 id: 7,597 points: {598 useState: 8,599 useReducer: 5,600 useCallback: 1,601 useImperativeHandle: 3,602 useEffect: 9,603 useRef: 8,604 useLayoutEffect: 7605 }606 }607 ]608 }609]610export const hooks = {611 useState: {612 description: 'Ð¢Ñ useState!',613 text: 'ÐозвÑаÑÐ°ÐµÑ Ð·Ð½Ð°Ñение Ñ ÑоÑÑоÑнием и ÑÑнкÑÐ¸Ñ Ð´Ð»Ñ ÐµÐ³Ð¾ обновлениÑ.',614 link: 'https://reactjs.org/docs/hooks-reference.html#usestate'615 },616 useReducer: {617 description: 'Ð¢Ñ useReducer!',618 text:619 'ÐлÑÑеÑнаÑива Ð´Ð»Ñ useState. ÐÑÐ¸Ð½Ð¸Ð¼Ð°ÐµÑ ÑедÑÑÐµÑ Ñипа (state, action) => newState и возвÑаÑÐ°ÐµÑ ÑекÑÑее ÑоÑÑоÑние в паÑе Ñ Ð¼ÐµÑодом dispatch. (ÐÑли Ð²Ñ Ð·Ð½Ð°ÐºÐ¾Ð¼Ñ Ñ Redux, Ð²Ñ Ñже знаеÑе, как ÑÑо ÑабоÑаеÑ.)',620 link: 'https://reactjs.org/docs/hooks-reference.html#usereducer'621 },622 useCallback: {623 description: 'Ð¢Ñ useCallback!',624 text: 'ÐозвÑаÑÐ°ÐµÑ Ð¼ÐµÐ¼Ð¾Ð¸Ð·Ð¸ÑованнÑй колбÑк.',625 link: 'https://reactjs.org/docs/hooks-reference.html#usecallback'626 },627 useImperativeHandle: {628 description: 'Ð¢Ñ useImperativeHandle!',629 text:630 'useImperativeHandle наÑÑÑÐ°Ð¸Ð²Ð°ÐµÑ Ð·Ð½Ð°Ñение ÑкземплÑÑа, коÑоÑое пÑедоÑÑавлÑеÑÑÑ ÑодиÑелÑÑким компоненÑам пÑи иÑполÑзовании ref. Ðак вÑегда, в болÑÑинÑÑве ÑлÑÑаев ÑледÑÐµÑ Ð¸Ð·Ð±ÐµÐ³Ð°ÑÑ Ð¸Ð¼Ð¿ÐµÑаÑивного кода, иÑполÑзÑÑÑего ÑÑÑлки. useImperativeHandle должен иÑполÑзоваÑÑÑÑ Ñ forwardRef:',631 link: 'https://reactjs.org/docs/hooks-reference.html#useimperativehandle'632 },633 useEffect: {634 description: 'Ð¢Ñ useEffect!',635 text:636 'ÐÑÐ¸Ð½Ð¸Ð¼Ð°ÐµÑ ÑÑнкÑиÑ, коÑоÑÐ°Ñ ÑодеÑÐ¶Ð¸Ñ Ð¸Ð¼Ð¿ÐµÑаÑивнÑй код, возможно, Ñ ÑÑÑекÑами.',637 link: 'https://reactjs.org/docs/hooks-reference.html#useeffect'638 },639 useRef: {640 description: 'Ð¢Ñ useRef!',641 text:642 'useRef возвÑаÑÐ°ÐµÑ Ð¸Ð·Ð¼ÐµÐ½ÑемÑй ref-обÑекÑ, ÑвойÑÑво .current коÑоÑого иниÑиализиÑÑеÑÑÑ Ð¿ÐµÑеданнÑм аÑгÑменÑом (initialValue). ÐозвÑаÑÑннÑй обÑÐµÐºÑ Ð±ÑÐ´ÐµÑ ÑоÑ
ÑанÑÑÑÑÑ Ð² ÑеÑение вÑего вÑемени жизни компоненÑа.',643 link: 'https://reactjs.org/docs/hooks-reference.html#useref'644 },645 useLayoutEffect: {646 description: 'Ð¢Ñ useLayoutEffect!',647 text:648 'СигнаÑÑÑа иденÑиÑна useEffect, но ÑÑÐ¾Ñ Ñ
Ñк запÑÑкаеÑÑÑ ÑинÑ
Ñонно поÑле вÑеÑ
изменений DOM. ÐÑполÑзÑйÑе его Ð´Ð»Ñ ÑÑÐµÐ½Ð¸Ñ Ð¼Ð°ÐºÐµÑа из DOM и ÑинÑ
Ñонного повÑоÑного ÑендеÑинга. ÐбновлениÑ, запланиÑованнÑе внÑÑÑи useLayoutEffect, бÑдÑÑ Ð¿Ð¾Ð»Ð½Ð¾ÑÑÑÑ Ð¿ÑÐ¸Ð¼ÐµÐ½ÐµÐ½Ñ ÑинÑ
Ñонно пеÑед Ñем, как бÑаÑÐ·ÐµÑ Ð¿Ð¾Ð»ÑÑÐ¸Ñ ÑÐ°Ð½Ñ Ð¾ÑÑÑеÑÑвиÑÑ Ð¾ÑÑиÑовкÑ.',649 link: 'https://reactjs.org/docs/hooks-reference.html#uselayouteffect'650 }...
usePerpetual.js
Source:usePerpetual.js
...28 const [status, setStatus] = useState("--")29 const [accumulatedFunding, setAccumulatedFunding] = useState("--")30 const [myDeposit, setMyDeposit] = useState("0")31 const shareToken = useERC20(shareTokenAddress, account, library, tick)32 const getStatus = useCallback(33 async () => {34 try {35 const result = await perpetualContract.status()36 switch (result) {37 case 0:38 return "Active"39 case 1:40 return "Emergency"41 case 2:42 return "Settlement"43 default:44 return "Unknown"45 }46 } catch (e) {47 return "Error"48 }49 },50 [perpetualContract, account]51 );52 const getShareTokenAddress = useCallback( async () => {53 try {54 return await ammContract.shareTokenAddress()55 } catch (e) {56 return null57 }58 },[ammContract, account])59 const getIndexPrice = useCallback(60 async () => {61 try {62 const result = await ammContract.indexPrice()63 return ethers.utils.formatEther(result.price)64 } catch (e) {65 return "0"66 }67 },68 [ammContract, account]69 );70 const getAccumulatedFunding = useCallback(71 async () => {72 try {73 const result = await ammContract.getAccumulatedFundingPerContract()74 return ethers.utils.formatEther(result)75 } catch (e) {76 return "0"77 }78 },79 [ammContract, account]80 );81 const getAvailableMargin = useCallback(82 async () => {83 try {84 const result = await ammContract.getAvailableMargin()85 return ethers.utils.formatEther(result)86 } catch (e) {87 return "0"88 }89 },90 [ammContract, account]91 );92 const getMarkPrice = useCallback(93 async () => {94 try {95 const output = await ammContract.getMarkPrice()96 return ethers.utils.formatEther(output)97 } catch (e) {98 return "0"99 }100 },101 [ammContract, account]102 );103 const getBuyPrice = useCallback(async (amount) => {104 const result = await ammContract.getBuyPricePublic(ethers.utils.parseEther(`${amount}`))105 return ethers.utils.formatEther(result)106 }, [ammContract, account])107 const getSellPrice = useCallback(async (amount) => {108 const result = await ammContract.getSellPricePublic(ethers.utils.parseEther(`${amount}`))109 return ethers.utils.formatEther(result)110 }, [ammContract, account])111 const deposit = useCallback(112 async (amount) => {113 return await perpetualContract.deposit(114 ethers.utils.parseEther(amount)115 )116 },117 [perpetualContract, account]118 );119 const withdraw = useCallback(120 async (amount) => {121 // TODO : increase gas price122 return await perpetualContract.withdraw(123 ethers.utils.parseEther(amount),124 {125 // gasPrice: 70000000000126 }127 )128 },129 [perpetualContract, account]130 );131 const getDeposit = useCallback(async () => {132 const result = await perpetualContract.totalRawCollateral(account)133 return ethers.utils.formatEther(result)134 }, [perpetualContract, account])135 const getDeadline = () => {136 return ((new Date().valueOf() / 1000) + 86400)137 }138 const getCurrentPrice = useCallback(async () => {139 const result = await ammContract.getCurrentPricePublic()140 return ethers.utils.formatEther(result)141 }, [ammContract, account])142 const buy = useCallback(async (amount) => {143 // TODO : increase gas price144 return await ammContract.buy(ethers.utils.parseEther(`${amount}`), ethers.utils.parseEther(`50000`), 9999999999999, {145 // gasPrice: 70000000000146 })147 }, [ammContract, account])148 const sell = useCallback(async (amount) => {149 // TODO : increase gas price150 return await ammContract.sell(ethers.utils.parseEther(`${amount}`), 0, 9999999999999, {151 // gasPrice: 70000000000152 })153 }, [ammContract, account])154 const addLiquidity = useCallback(async (amount) => {155 // TODO : increase gas price156 return await ammContract.addLiquidity(ethers.utils.parseEther(`${amount}`), { 157 // gasPrice: 70000000000158 })159 }, [ammContract, account])160 const removeLiquidity = useCallback(async (lpAmount) => {161 // TODO : increase gas price162 return await ammContract.removeLiquidity(ethers.utils.parseEther(`${lpAmount}`), {163 // gasPrice: 70000000000164 })165 }, [ammContract, account])166 const getPosition = useCallback(async () => {167 168 const size = await perpetualContract.getPositionSize(account)169 const side = await perpetualContract.getPositionSide(account)170 const positionEntryValue = await perpetualContract.getPositionEntryValue(account)171 let pnl = 0172 if (side === 2) {173 //long174 pnl = (Number(markPrice) * Number(ethers.utils.formatEther(size))) - Number(ethers.utils.formatEther(positionEntryValue))175 } else if (side === 1) {176 //short177 pnl = Number(ethers.utils.formatEther(positionEntryValue)) - (Number(markPrice) * Number(ethers.utils.formatEther(size)))178 }179 return {180 size : ethers.utils.formatEther(size),...
useApi.js
Source:useApi.js
2import { useAxiosContext } from '@hooks/useAxiosContext'3const useApi = () => {4 const { auth, instance } = useAxiosContext()5 const authApi = {6 signUp: useCallback(7 userInfo => {8 return instance.post('/members', userInfo)9 },10 [instance],11 ),12 loginEmail: useCallback(13 userInfo => {14 return instance?.post('/members/login', userInfo)15 },16 [instance],17 ),18 loginKakao: useCallback(19 code => {20 return instance.get(`/oauth/callback/kakao?code=${code}`)21 },22 [instance],23 ),24 checkDuplicates: useCallback(25 email => {26 return instance.get(`/members?email=${email}`)27 },28 [instance],29 ),30 withdrawal: useCallback(31 password => {32 return auth.delete('/members', password)33 },34 [auth],35 ),36 getUserInfo: useCallback(() => {37 return auth.get('/members/me')38 }, [auth]),39 getUserProfile: useCallback(() => {40 return auth.get('/members/mypage')41 }, [auth]),42 getOtherUserProfile: useCallback(43 merberId => {44 return instance.get(`/members/${merberId}`)45 },46 [instance],47 ),48 modifyUserInfo: useCallback(49 userInfo => {50 return auth.patch('/members/me', userInfo)51 },52 [auth],53 ),54 }55 const userApi = {56 getUserLikeArticles: useCallback(57 ({ tradeStatusCode, params }) => {58 return auth.get(59 `/articles/like-articles?tradeStatusCode=${tradeStatusCode}`,60 { params },61 )62 },63 [auth],64 ),65 getUserOfferArticles: useCallback(66 ({ tradeStatusCode, params }) => {67 return auth.get(`/articles/offers?tradeStatusCode=${tradeStatusCode}`, {68 params,69 })70 },71 [auth],72 ),73 getUserTradingAtricles: useCallback(74 ({ memberId, params }) => {75 return instance.get(76 `/articles?memberId=${memberId}&tradeStatusCode=4`,77 {78 params,79 },80 )81 },82 [instance],83 ),84 getUserCompletedArticles: useCallback(85 ({ memberId, params }) => {86 return instance.get(87 `/articles?memberId=${memberId}&tradeStatusCode=8`,88 {89 params,90 },91 )92 },93 [instance],94 ),95 getUserBuyReviews: useCallback(96 ({ memberId, params }) => {97 return auth.get(`/reviews?memberId=${memberId}&role=buyer`, {98 params,99 })100 },101 [auth],102 ),103 getUserSellReviews: useCallback(104 ({ memberId, params }) => {105 return auth.get(`/reviews?memberId=${memberId}&role=seller`, {106 params,107 })108 },109 [auth],110 ),111 getUserReview: useCallback(112 articleId => {113 return auth.get(`/reviews/me?articleId=${articleId}`)114 },115 [auth],116 ),117 postReview: useCallback(118 ({ articleId, payload }) => {119 return auth.post(`/reviews?articleId=${articleId}`, payload)120 },121 [auth],122 ),123 }124 const reviewApi = {125 getBuyReviews: useCallback(126 memberId => {127 return instance.get(`/reviews?memberId=${memberId}&status=buy`)128 },129 [instance],130 ),131 getSellReviews: useCallback(132 memberId => {133 return instance.get(`/reviews?memberId=${memberId}&status=sell`)134 },135 [instance],136 ),137 postReview: useCallback(138 ({ offerId, memberId, content }) => {139 return auth.post(140 `/reviews/offers/${offerId}?toMember=${memberId}`,141 content,142 )143 },144 [auth],145 ),146 }147 const articleApi = {148 searchArticlesWithAuth: useCallback(149 params => {150 return auth.get(`/search`, { params })151 },152 [auth],153 ),154 searchArticles: useCallback(155 params => {156 return instance.get(`/search`, { params })157 },158 [instance],159 ),160 searchFilterArticles: useCallback(161 params => {162 return auth.get(`/search/filters`, { params })163 },164 [auth],165 ),166 editArticle: useCallback(167 articleInfo => {168 return auth.put('/articles', articleInfo)169 },170 [auth],171 ),172 getArticle: useCallback(173 ({ articleId, params }) => {174 return instance.get(`/articles${articleId ? `/${articleId}` : ''}`, {175 params,176 })177 },178 [instance],179 ),180 getTradingAtricles: useCallback(181 params => {182 return auth.get('/articles?tradeStatusCode=4', { params })183 },184 [auth],185 ),186 getArticleOfCategory: useCallback(187 ({ categoryCode, params }) => {188 return instance.get(`/articles?categoryCode=${categoryCode}`, {189 params,190 })191 },192 [instance],193 ),194 getOffersList: useCallback(195 articleId => {196 return auth.get(`/articles/${articleId}/offers`)197 },198 [auth],199 ),200 getOfferListPage: useCallback(201 ({ articleId, params }) => {202 return auth.get(`/articles/${articleId}/offers`, { params })203 },204 [auth],205 ),206 getImgUrlList: useCallback(207 articleId => {208 return instance.get(`/articles/${articleId}/imageUrls`)209 },210 [instance],211 ),212 changeTradeStatus: useCallback(213 ({ articleId, option }) => {214 return auth.patch(`/articles/${articleId}/tradeStatus`, option)215 },216 [auth],217 ),218 deleteArticle: useCallback(219 articleId => {220 return auth.delete(`/articles/${articleId}`)221 },222 [auth],223 ),224 toggleLikeArticle: useCallback(225 articleId => {226 return auth.put(`/articles/${articleId}/like`)227 },228 [auth],229 ),230 postOffer: useCallback(231 ({ articleId, price }) => {232 return auth.post(`/articles/${articleId}/offers`, price)233 },234 [auth],235 ),236 selectOffer: useCallback(237 offerId => {238 return auth.patch(`/articles/offers/${offerId}`)239 },240 [auth],241 ),242 getArticleUserID: useCallback(243 articleId => {244 return auth.get(`/articles/${articleId}`)245 },246 [auth],247 ),248 getArticlesInfos: useCallback(() => {249 return instance.get('articles/infos')250 }, [instance]),251 }252 const messageApi = {253 postMessageToOffer: useCallback(254 ({ memberId, offerId, articleId, content }) => {255 return auth.post(256 `/messages/member/${memberId}/offerId/${offerId}?articleId=${articleId}`,257 content,258 )259 },260 [auth],261 ),262 postMessage: useCallback(263 ({ messageRoomId, message }) => {264 return auth.post(`/messages/messageRoom/${messageRoomId}`, message)265 },266 [auth],267 ),268 getMessageList: useCallback(269 ({ messageRoomId, params }) => {270 return auth.get(`/messages/messageRoom/${messageRoomId}/contents`, {271 params,272 })273 },274 [auth],275 ),276 getMessageRoomInfo: useCallback(277 ({ messageRoomId }) => {278 return auth.get(279 `/messages/messageRoom/${messageRoomId}/messageRoomInfo`,280 )281 },282 [auth],283 ),284 deleteMessageBox: useCallback(285 ({ messageRoomId }) => {286 return auth.delete(` /messages/messageRoomId/${messageRoomId}`)287 },288 [auth],289 ),290 getMessageBox: useCallback(() => {291 return auth.get('/messages/messageBox')292 }, [auth]),293 }294 const imgApi = {295 convertImgList: useCallback(296 images => {297 return instance.post('/articles/imageUrls', images)298 },299 [instance],300 ),301 convertImg: useCallback(302 image => {303 return instance.post('/members/imageUrls', image)304 },305 [instance],306 ),307 }308 return { authApi, userApi, reviewApi, articleApi, messageApi, imgApi }309}...
Stammdaten.js
Source:Stammdaten.js
...39 const location = store.location.toJSON()40 const activeLocation = location[0]41 const { table, id, rows, fetch } = store.table42 const tableName = table ? tableNameObject[table] || table : ''43 const fetchAbteilungen = useCallback(() => fetch('abteilung'), [fetch])44 const fetchInterne = useCallback(() => fetch('interne'), [fetch])45 const fetchExterne = useCallback(() => fetch('externe'), [fetch])46 const fetchAktenstandort = useCallback(() => fetch('aktenstandort'), [fetch])47 const fetchGeschaeftsart = useCallback(() => fetch('geschaeftsart'), [fetch])48 const fetchParlVorstossTyp = useCallback(() => fetch('parlVorstossTyp'), [49 fetch,50 ])51 const fetchRechtsmittelInstanz = useCallback(52 () => fetch('rechtsmittelInstanz'),53 [fetch],54 )55 const fetchRechtsmittelErledigung = useCallback(56 () => fetch('rechtsmittelErledigung'),57 [fetch],58 )59 const fetchStatus = useCallback(() => fetch('status'), [fetch])60 const onClickInsert = useCallback(() => rows.insert(table), [rows, table])61 const onClickDelete = useCallback(() => rows.delete(table, id), [62 id,63 rows,64 table,65 ])66 const isActive = activeLocation === 'table'67 return (68 <StamdatenContainer active={isActive}>69 <UncontrolledDropdown nav inNavbar active={isActive}>70 <DropdownToggle nav caret>71 {table ? (72 <span>73 {tableName}74 <Sup>{table ? rows[table].length : 0}</Sup>75 </span>...
buff.js
Source:buff.js
...6}7Buff.prototype.use = function(player) {8 if (!!this.useCallback) {9 player.addBuff(this);10 this.useCallback(player);11 if (this.timeout > 0){12 if (!!this.unuseCallback) {13 setTimeout(function(){14 player.removeBuff(this);15 this.unuseCallback(player);16 }, this.timeout);17 }18 }19 }20};21var ConfuseBuff = (function() {22 return function(timeout) {23 return new Buff({24 type: 'confuse',25 useCallback: function(player){26 player.confused = true;27 },28 unuseCallback: function(player){29 player.confused = false;...
useAuth.js
Source:useAuth.js
...3import * as authActions from '../store/actions';4const useAuth = (getKey = null) => {5 const data = useSelector((state) => state.auth);6 const dispatch = useDispatch();7 const hasPermission = useCallback(8 (permission) => data.permissions.includes(permission),9 [data]10 );11 const login = useCallback((params) => dispatch(authActions.login(params)), [12 dispatch13 ]);14 const refresh = useCallback(15 (params) => dispatch(authActions.refreshToken(params)),16 [dispatch]17 );18 const changeLogin = useCallback(19 (params) => dispatch(authActions.changeLogin(params)),20 [dispatch]21 );22 const logout = useCallback(() => dispatch(authActions.logout()), [dispatch]);23 const isAuthenticated = useMemo(24 () =>25 !!(26 data.expirationDate &&27 data.expirationDate > new Date() &&28 data.accessToken29 ),30 [data.expirationDate, data.accessToken]31 );32 const getClaim = useCallback(33 (type) => data.claims.find((c) => c.type === type),34 [data]35 );36 const getClaims = useCallback(37 (type) => data.claims.filter((c) => c.type === type),38 [data]39 );40 const hasClaim = useCallback(41 (type) => data.claims.findIndex((c) => c.type === type) >= 0,42 [data]43 );44 const hasRole = useCallback((...roles) => roles.includes(data.user.role), [45 data46 ]);47 const isAdmin = () => {48 return data.user && data.user.role === 'Admin';49 };50 let key = null;51 try {52 key = getKey ? getKey(data) : data.user.id;53 } catch (error) {54 key = 'auth.provider';55 }56 return {57 ...data,58 key,...
index.js
Source:index.js
1import { useRef, useEffect, useCallback } from 'react'2const useTimingEvents = () => {3 const timeoutRefs = useRef({})4 const intervalRefs = useRef({})5 const addTimeout = useCallback((timeout, key) => {6 timeoutRefs.current[key || timeout] = timeout7 return timeout8 }, [])9 const addInterval = useCallback((interval, key) => {10 intervalRefs.current[key || interval] = interval11 return interval12 }, [])13 const getTimeout = useCallback((key) => {14 return timeoutRefs.current[key]15 }, [])16 const getInterval = useCallback((key) => {17 return intervalRefs.current[key]18 }, [])19 const clearTimeout = useCallback((key) => {20 window.clearTimeout(getTimeout(key) || key)21 delete timeoutRefs.current[key]22 }, [])23 const clearInterval = useCallback((key) => {24 window.clearInterval(getInterval(key) || key)25 delete intervalRefs.current[key]26 }, [])27 const clearAllTimeout = useCallback(() => {28 Object.keys(timeoutRefs.current).forEach(key => {29 clearTimeout(key)30 })31 timeoutRefs.current = {}32 }, [])33 const clearAllInterval = useCallback(() => {34 Object.keys(intervalRefs.current).forEach(key => {35 clearInterval(key)36 })37 intervalRefs.current = {}38 }, [])39 useEffect(() => {40 return () => {41 clearAllTimeout()42 clearAllInterval()43 }44 }, [])45 return {46 addTimeout,47 addInterval,...
callback.js
Source:callback.js
...7 * 1.é¿å
ç»ä»¶çéå¤æ¸²æ8 *9 * useMemo useCallback10 * åæ ·ç¨å°çæ¯ç¼åææ¯ï¼ useCallback ç¼åçæ¯ä¸ä¸ªå½æ°ï¼å½æ°å¯ä»¥æ§è¡11 * useCallback(fnï¼[å¯ä»¥ä¸å])12 *13 *14 */15import React, {useState,useCallback} from 'react';1617const Callback = () => {18 const [count, setCount] = useState(100);19 let callback = useCallback(() => {20 console.log('useCallback');21 console.log(count)22 return count;2324 },[]);25 return (26 <div>27 <h1>useCallback</h1>28 <p>{count}</p>29 <p>è¿åçå¼ï¼{callback()}</p>30 <button31 onClick={() => {32 setCount((c) => c + 20)33 }}
...
Using AI Code Generation
1const qawolf = require("qawolf");2describe("test", () => {3 let browser;4 let context;5 let page;6 beforeAll(async () => {7 browser = await qawolf.launch();8 });9 afterAll(async () => {10 await browser.close();11 });12 beforeEach(async () => {13 context = await browser.newContext();14 page = await context.newPage();15 });16 afterEach(async () => {17 await qawolf.stopVideos();18 await page.close();19 await context.close();20 });21 it("test", async () => {22 await page.click("input[name=q]");23 await page.fill("input[name=q]", "qawolf");24 await page.press("input[name=q]", "Enter");25 await page.click("text=QA Wolf: Automated tests for your website");26 await page.click("text=Get Started");27 await page.click("text=Sign Up");28 await page.click("button");29 await page.fill("input[name=email]", "
Using AI Code Generation
1const { launch, click, type, closeBrowser } = require("qawolf");2const selectors = require("./selectors/test.json");3describe('test', () => {4 let browser;5 beforeAll(async () => {6 });7 afterAll(async () => {8 await closeBrowser();9 });10 it("test",
Using AI Code Generation
1const { launch, press, type, closeBrowser } = require("qawolf");2const selectors = require("./selectors/test");3describe('test', () => {4 let browser;5 beforeAll(async () => {6 browser = await launch();7 });8 afterAll(async () => {9 await closeBrowser();10 });11 it('test', async () => {12 const page = await browser.newPage();13 await type(page, selectors[0], "hello");14 await press(page, selectors[1]);15 await page.waitForSelector(selectors[2]);16 await page.click(selectors[2]);17 });18});19 "#rso > div:nth-child(1) > div > div > div > div > div.r > a > h3"20];
Using AI Code Generation
1const { launch, page } = require("qawolf");2const { test, expect } = require("@playwright/test");3test("test", async () => {4 await page.click("input[title=\"Search\"]");5 await page.fill("input[title=\"Search\"]", "test");6 await page.click("text=Search");7 await page.click("text=Test - Wikipedia");
Using AI Code Generation
1const { register, login } = require("./utils");2const { test, expect } = require("@playwright/test");3const { launch } = require("qawolf");4test.describe("Login", () => {5 let browser;6 let context;7 let page;8 beforeAll(async () => {9 browser = await launch();10 });11 afterAll(async () => {12 await browser.close();13 });14 beforeEach(async () => {15 context = await browser.newContext();16 page = await context.newPage();17 });18 afterEach(async () => {19 await page.close();20 await context.close();21 });22 test("Login", async () => {23 await register(page);24 await login(page);25 await page.click("text=Logout");26 });27});28const { test, expect } = require("@playwright/test");29const { launch } = require("qawolf");30let browser;31let context;32let page;33beforeAll(async () => {34 browser = await launch();35});36afterAll(async () => {37 await browser.close();38});39beforeEach(async () => {40 context = await browser.newContext();41 page = await context.newPage();42});43afterEach(async () => {44 await page.close();45 await context.close();46});47test("Register", async () => {48 await page.click("text=Register");49 await page.click("input[name='username']");50 await page.fill("input[name='username']", "test");51 await page.click("input[name='email']");52 await page.fill("input[name='email']", "
Using AI Code Generation
1const { launch, press, text, type, click, hover, page, browser, context } = require("qawolf");2const selectors = require("./selectors/test.json");3const assert = require("assert");4const test = async () => {5 await click(selectors["#tsf > div:nth-child(2) > div > div.RNNXgb > div > div.a4bIc > input"]);6 await type(selectors["#tsf > div:nth-child(2) > div > div.RNNXgb > div > div.a4bIc > input"], "test");7 await press("Enter");8 await click(selectors["#rso > div:nth-child(1) > div > div > div > div > div.r > a > h3"]);9 await click(selectors["body > div:nth-chil
Using AI Code Generation
1const { useCallback } = require("qawolf");2const callback = useCallback(3 async (page, selector) => {4 },5);6const callback = useCallback(7 async (page, selector) => {8 },9);10const callback = useCallback(11 async (page, selector) => {12 },13);14const callback = useCallback(15 async (page, selector) => {16 },17);18const callback = useCallback(19 async (page, selector) => {20 },21);
Using AI Code Generation
1const { code } = await createTest({2 code: `const { test, expect } = require("@playwright/test");3test("google", async ({ page }) => {4 await page.fill('input[name="q"]', "qawolf");5 await page.click('input[type="submit"]');6 await page.waitForSelector("text=QAWolf: Open Source E2E Testing Tool");7 await page.click("text=QAWolf: Open Source E2E Testing Tool");8 await page.waitForSelector("text=QAWolf: Open Source E2E Testing Tool");9 const element = await page.$("text=QAWolf: Open Source E2E Testing Tool");10 expect(element).toBeTruthy();11});`,12});13const browser = await launch();14const context = await browser.newContext();15const page = await context.newPage();16await run({17 code: `const { test, expect } = require("@playwright/test");18test("google", async ({ page }) => {19 await page.fill('input[name="q"]', "qawolf");20 await page.click('input[type="submit"]');21 await page.waitForSelector("text=QAWolf: Open Source E2E Testing Tool");22 await page.click("text=QAWolf: Open Source E2E Testing Tool");23 await page.waitForSelector("text=QAWolf: Open Source E2E Testing Tool");24 const element = await page.$("text=QAWolf: Open Source E2E Testing Tool");25 expect(element).toBeTruthy();26});`,27});28const browser = await launch();29const context = await browser.newContext();30const page = await context.newPage();31await runInDocker({32 code: `const { test, expect } = require("@playwright/test");33test("google", async ({ page }) => {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!