";display:inline-block}.typography-module--codeHeading--3thrs .typography-module--videoLink--FyHMi,.typography-module--h5--1sUpK .typography-module--videoLink--FyHMi{background:none;border:1px solid var(--color-secondary);color:#fff;font-family:Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;font-size:14px;margin-bottom:-5px;margin-left:15px;padding:5px 10px;text-decoration:none;text-transform:uppercase}.typography-module--h1--3Qud7{border-bottom:2px solid var(--color-secondary);display:inline-block;font-size:24px;font-weight:400;margin:40px auto;padding-bottom:5px}.typography-module--h5--1sUpK{border-bottom:1px solid var(--color-light-blue);font-size:18px;font-weight:500;margin:50px 0 10px;padding-bottom:15px;text-align:left}.typography-module--h5--1sUpK>code{font-size:18px!important}.typography-module--typeText--2ZjkH{color:var(--color-light-pink)!important;font-family:monospace;font-size:14px;font-weight:400}.typography-module--note--2CfRx{color:var(--color-light-pink)}.typography-module--codeBlock--2uKd_{display:block;padding:10px}.typography-module--error--opBvi{color:var(--color-light-pink);font-size:12px}@media (min-width:768px){.typography-module--h1--3Qud7{font-size:36px;font-weight:700}.typography-module--heading--2ITQI,.typography-module--headingWithTopMargin--3T_s4{font-size:55px!important;margin:80px auto 10px}.typography-module--subHeading--3mj4P{font-size:18px;margin-bottom:20px;margin-top:5px;max-width:575px}.typography-module--title--3Ob7c{font-size:1.3rem;line-height:1.5;margin-top:20px}h2.typography-module--title--3Ob7c{margin-top:40px}.typography-module--headingWithTopMargin--3T_s4{margin-top:70px}.typography-module--questionTitle--BKuZq{border-left:5px solid var(--color-light-pink);line-height:1;padding-left:10px}}@media (min-width:1024px){.typography-module--h1--3Qud7{border-bottom:3px solid var(--color-secondary);font-size:50px;line-height:1.3;margin-top:60px}.typography-module--homeParagraph--2WGV8{font-size:20px;line-height:1.5}.typography-module--heading--2ITQI,.typography-module--headingWithTopMargin--3T_s4{margin-top:20px}.typography-module--headingWithTopMargin--3T_s4{margin-top:70px}}.SideMenu-module--menu--2pmVQ{display:none;position:relative}.SideMenu-module--arrow--kte6y{color:var(--color-light-pink);position:relative}.SideMenu-module--arrowLast--Ln3zG:before{border-left:1px solid #ec5990;content:"";height:43%;left:0;position:absolute;top:0}.SideMenu-module--size--3tZ4v{color:currentColor;font-size:10px;margin-left:5px}@media (min-width:768px){.SideMenu-module--menu--2pmVQ{display:block}.SideMenu-module--menu--2pmVQ>div{margin-top:-10px;position:fixed}.SideMenu-module--menu--2pmVQ>div>ul{height:calc(100vh - 236px);margin-top:0;max-width:230px;overflow-y:auto;padding:0}.SideMenu-module--menu--2pmVQ>div>ul>li{display:flex;font-size:15px;line-height:22px;padding-bottom:8px}.SideMenu-module--menu--2pmVQ>div>ul>li>a{line-height:20px;padding-left:6px;text-decoration:none}.SideMenu-module--menu--2pmVQ>div>ul>li>a,.SideMenu-module--menu--2pmVQ>div>ul>li>button{background:none;border:none;border-bottom:1px solid transparent;color:currentColor;cursor:pointer;margin:0 7px;padding:0;text-align:left;transition:all .3s}.SideMenu-module--menu--2pmVQ>div>ul>li>a:hover,.SideMenu-module--menu--2pmVQ>div>ul>li>button:hover{border-bottom:1px solid var(--color-light-pink)}.SideMenu-module--lightMenu--F0Lxu>div>ul>li>a,.SideMenu-module--lightMenu--F0Lxu>div>ul>li>button{background:none;border:none;border-bottom:1px solid transparent;color:var(--color-black);cursor:pointer;text-align:left;transition:all .3s}.SideMenu-module--lightMenu--F0Lxu>div>ul>li>a:hover,.SideMenu-module--lightMenu--F0Lxu>div>ul>li>button:hover{background:none;border-bottom:1px solid var(--color-light-pink)!important}}@media (min-height:920px){.SideMenu-module--menu--2pmVQ>div>ul>li{padding-bottom:12px}}.SideMenu-module--titleList--ydVFH{width:200px}.SideMenu-module--code--lBWpe{color:var(--color-light-pink);display:inline-table;font-size:12px;position:relative;top:2px}@media (min-width:1024px){.SideMenu-module--menu--2pmVQ{margin-top:-75px}.SideMenu-module--menu--2pmVQ>div>ul{margin-top:0;max-width:260px}.SideMenu-module--menu--2pmVQ>ul{height:calc(100vh - 200px);max-width:250px}.SideMenu-module--titleList--ydVFH{margin-bottom:20px;width:250px}.SideMenu-module--titleList--ydVFH>h2{padding:0}}@media (min-width:1280px){.SideMenu-module--menu--2pmVQ>ul{max-width:270px}}.SideMenu-module--menu--2pmVQ li.SideMenu-module--menuItem--eLHu4{display:block}.SideMenu-module--menuItem--eLHu4 code{position:relative;top:-1px}.SideMenu-module--menuItem--eLHu4 li{padding:3px 0}.SideMenu-module--menu--2pmVQ li.SideMenu-module--menuItem--eLHu4>ul{padding-left:10px}.SideMenu-module--menu--2pmVQ li.SideMenu-module--menuItem--eLHu4>ul>li{border-left:1px solid var(--color-light-pink);padding-left:20px;position:relative}.SideMenu-module--menu--2pmVQ li.SideMenu-module--menuItem--eLHu4>ul>li:last-child{border-left:none;position:relative}.SideMenu-module--menu--2pmVQ li.SideMenu-module--menuItem--eLHu4>ul>li:last-child:after{border-left:1px solid var(--color-light-pink);bottom:0;content:"";height:58%;left:0;position:absolute;top:0}.SideMenu-module--menu--2pmVQ li.SideMenu-module--menuItem--eLHu4>ul>li:before{border-bottom:1px solid var(--color-light-pink);bottom:12px;content:"";left:0;position:absolute;width:10px}.SideMenu-module--menu--2pmVQ li.SideMenu-module--menuItem--eLHu4>ul a{border-bottom:1px solid transparent;color:currentColor;text-decoration:none}.SideMenu-module--menu--2pmVQ li.SideMenu-module--menuItem--eLHu4>ul a:hover{border-bottom:1px solid var(--color-light-pink)}.SideMenu-module--menu--2pmVQ li.SideMenu-module--menuItem--eLHu4>ul>li{list-style:none}.SideMenu-module--menu--2pmVQ ul li a.SideMenu-module--isActive--2gopj{border-bottom:1px solid var(--color-secondary)}.button-module--codeAsLink--bxSY7,.button-module--links--is5hd{color:var(--color-link)}.button-module--codeAsLink--bxSY7{-webkit-appearance:none;appearance:none;background:none;border:none;color:var(--color-link)!important;cursor:pointer;padding:0;text-decoration:underline}.button-module--buttonsGroup--1vdIq{grid-column-gap:20px;display:grid;grid-template-columns:repeat(2,1fr);margin:0 auto}.button-module--button--3HOie,.button-module--darkButton--1KQx3,.button-module--pinkButton--Vcc3P,.button-module--primaryButton--268Pl{-webkit-appearance:none;border-radius:4px;color:#fff;cursor:pointer;display:inline-block;font-size:16px;font-weight:400;line-height:1;margin:20px 0;padding:16px 10px;transition:all .3s}.button-module--primaryButton--268Pl{background:var(--color-primary);border:1px solid var(--color-light-blue);box-sizing:border-box}a.button-module--primaryButton--268Pl{text-decoration:none}a.button-module--primaryButton--268Pl:hover{color:#fff}.button-module--darkButton--1KQx3,.button-module--pinkButton--Vcc3P{background:var(--color-light-pink);border:1px solid var(--color-light-pink);letter-spacing:.5rem;text-transform:uppercase;width:100%}.button-module--pinkButton--Vcc3P:hover{background:var(--color-secondary)}.button-module--darkButton--1KQx3{background:#000;border:1px solid var(--color-light-pink);color:#fff}.button-module--darkButton--1KQx3:hover{background:var(--color-primary);border:1px solid var(--color-secondary)}.button-module--darkButton--1KQx3:active{background:#000}@-webkit-keyframes button-module--moving--3ebu_{0%{-webkit-transform:translateX(0);transform:translateX(0)}to{-webkit-transform:translateX(5px);transform:translateX(5px)}}@keyframes button-module--moving--3ebu_{0%{-webkit-transform:translateX(0);transform:translateX(0)}to{-webkit-transform:translateX(5px);transform:translateX(5px)}}.button-module--primaryButton--268Pl:hover>span{-webkit-animation:button-module--moving--3ebu_ .4s linear infinite;animation:button-module--moving--3ebu_ .4s linear infinite;-webkit-animation-direction:alternate;animation-direction:alternate;display:inline-block}.button-module--primaryButton--268Pl:active{background:#000}.button-module--primaryButton--268Pl:hover{border:1px solid var(--color-secondary);box-shadow:0 0 5px #000}@media (min-width:768px){.button-module--primaryButton--268Pl{font-size:18px;font-weight:400;margin:40px 0;padding:15px 30px}.button-module--buttonsGroup--1vdIq{grid-column-gap:30px}}.CodeArea-module--buttonWrapper--1HGGF{display:flex;position:absolute;right:5px;top:10px}.CodeArea-module--button--3AIyz{align-items:center;border:none;border-radius:0;color:#fff;cursor:pointer;display:none;font-size:13px;height:34px;margin:0 3px;padding:0 10px;right:20px;text-transform:uppercase;top:10px;z-index:1}.CodeArea-module--codeLink--2D_Ac{background:var(--color-light-blue);border:1px solid transparent}.CodeArea-module--button--3AIyz:hover{background:var(--color-secondary);color:#fff}@media (min-width:768px){.CodeArea-module--button--3AIyz{display:flex}}.CodeArea-module--copyButton--3tysf{background:none;border:1px solid transparent;color:currentColor}.CodeArea-module--active--2oXJ5,.CodeArea-module--copyButton--3tysf:hover{background:none;border:1px solid var(--color-secondary);color:#fff}.CodeArea-module--active--2oXJ5,.CodeArea-module--copyButton--3tysf:hover span{background:var(--color-primary)}.CodeArea-module--linkToSandBox--200M6{color:inherit;line-height:2;right:115px;text-decoration:none}.CodeArea-module--linkToSandBox--200M6>svg{display:inline-block;height:18px;margin-right:8px;position:relative}.CodeArea-module--wrapper--lRtzy pre{line-height:1.5!important}.CodeArea-module--wrapper--lRtzy pre code{display:none}.CodeArea-module--wrapper--lRtzy pre code.CodeArea-module--showCode--PD_Hc{display:block}.GetStarted-module--installCode--2-Ykx{background:var(--color-button-blue)!important;border-radius:4px;display:block;margin-top:20px;padding:13px 20px}.GetStarted-module--lightInstallCode--1rUYD{background:#fff!important;border:1px solid var(--color-black)}.GetStarted-module--copyButton--2Zctn{background:var(--color-light-blue);border:1px solid transparent;color:#fff;cursor:pointer;display:none;float:right;font-size:13px;margin-top:-2px;text-transform:uppercase}.GetStarted-module--copyButton--2Zctn:hover{background:none;border:1px solid var(--color-secondary);color:#fff}.GetStarted-module--copyButton--2Zctn:hover span{background:var(--color-primary)}@media (min-width:768px){.GetStarted-module--copyButton--2Zctn{display:inline-block}}.table-module--table--3y8N_{border-collapse:collapse;margin-top:15px}.table-module--table--3y8N_ td{line-height:1.4;padding:6px 15px 6px 0}.table-module--table--3y8N_ td>h5:first-child,.table-module--table--3y8N_ td>p:first-child,.table-module--table--3y8N_ td>ul:first-child,.table-module--table--3y8N_ td>ul li:first-child>p{margin-top:0!important}.table-module--table--3y8N_ td>p:last-child{margin-bottom:0}.table-module--table--3y8N_ td:last-child{padding-right:0}.table-module--table--3y8N_ td>pre{margin:0}.table-module--tableWrapper--2E1uV{-webkit-overflow-scrolling:touch;overflow-x:auto;overflow-y:hidden}@media (min-width:768px){.table-module--mobileTypeText--1dW0f{display:inline;margin-top:0}.table-module--tableWrapper--2E1uV::-webkit-scrollbar{height:8px}.table-module--tableWrapper--2E1uV::-webkit-scrollbar-track{background:var(--color-button-blue);border-radius:10px}.table-module--tableWrapper--2E1uV::-webkit-scrollbar-thumb{background:var(--color-medium-blue);border-radius:10px}.table-module--tableWrapper--2E1uV::-webkit-scrollbar-thumb:hover{background:var(--color-light-pink)}}.ApiRefTable-module--fieldset--2ucBa{border:1px solid var(--color-light-blue);border-radius:4px;padding:10px 15px}.ApiRefTable-module--fieldset--2ucBa>legend{padding:0 10px;text-align:center}.ApiRefTable-module--fieldset--2ucBa>label{cursor:pointer;display:block;padding-bottom:15px}.ApiRefTable-module--fieldset--2ucBa>label:nth-child(2){padding-top:10px}.ApiRefTable-module--fieldset--2ucBa>label>input{margin-right:10px;position:relative;top:-2px}.container-module--container--3b9tj{padding-top:45px}.container-module--subContainer--2lbT3{margin:0 auto;max-width:768px}.container-module--centerContent--6IkFK{margin:0 auto;max-width:1024px;text-align:center}.container-module--centerContent--6IkFK svg{display:none}.container-module--wrapper--2l_Gi{margin:0 auto;max-width:1235px;overflow:hidden;padding:0 15px 100px 20px;position:relative}.container-module--centerContent--6IkFK p{margin:0 auto;max-width:730px}.container-module--centerContent--6IkFK h3{margin:0}@media (min-width:768px){.container-module--container--3b9tj{padding-top:0}.container-module--centerContent--6IkFK svg{display:block;margin:100px auto -30px;text-align:center;width:85px}.container-module--wrapper--2l_Gi{display:grid;grid-template-columns:250px minmax(0,1fr)}}@media (min-width:1024px){.container-module--wrapper--2l_Gi{display:grid;grid-template-columns:300px minmax(0,1fr)}.container-module--centerContent--6IkFK svg{margin:100px auto -50px}}.Form-module--code--3A7FS{font-size:.7rem;line-height:1.6;padding:0 20px;white-space:pre-wrap}.Form-module--wrapper--iaj-d{grid-column-gap:40px;display:grid;grid-template-columns:repeat(auto-fit,minmax(10rem,1fr));margin:20px auto 0;max-width:1440px;min-height:700px;transition:all 1s}.Form-module--demoForm--1H3vj{flex:1 1}.Form-module--demoForm--1H3vj>input,.Form-module--demoForm--1H3vj>select,.Form-module--input--2XLhM{border-radius:4px;box-sizing:border-box;display:block;font-size:.9rem;margin-bottom:10px;padding:6px 10px;width:100%}.Form-module--demoForm--1H3vj>select:not([multiple]){height:43px}.TabGroup-module--buttonTabGroup--2nb02{display:grid;grid-auto-flow:column}.TabGroup-module--buttonTabGroup--2nb02>button{background:var(--color-primary);background:#000;border:none;border-top:1px solid var(--color-secondary);color:#fff;font-size:12px;padding:5px 8px;text-transform:uppercase;transition:all .3s}.TabGroup-module--buttonTabGroup--2nb02>button:nth-child(n+2){margin-left:3px}.TabGroup-module--buttonTabGroup--2nb02>button:hover{background:var(--color-secondary)}.TabGroup-module--buttonTabGroup--2nb02>button:disabled{background:var(--color-primary);cursor:not-allowed}.TabGroup-module--lightButtonTabGroup--1ldh1>button{background:#fff;color:var(--color-black)}.TabGroup-module--lightButtonTabGroup--1ldh1>button:disabled,.TabGroup-module--lightButtonTabGroup--1ldh1>button:hover{color:#fff}@media (min-width:768px){.TabGroup-module--buttonTabGroup--2nb02>button{padding:5px 20px}}.Header-module--logo--kAPp0{fill:#fff;background:var(--color-light-pink);border:8px solid #fff;border-radius:20px;height:80px;margin:-50px auto 0;padding:15px}.Header-module--desktopLogo--2dR5M{background:var(--color-light-pink);border:4px solid #fff;border-radius:12px;display:none;height:60px;margin-right:5px;padding:8px;position:relative;top:10px}.Header-module--head--LS_wO{align-items:center;display:flex;flex-direction:column;height:100vh;justify-content:center}.Header-module--videoHeading--363Ps{border-bottom:2px solid var(--color-secondary);display:block;font-weight:400;line-height:2;margin-bottom:0;text-align:center}.Header-module--toggleGroup--25yDV{border:1px solid var(--color-light-blue);border-radius:4px;display:none;text-align:center}.Header-module--toggleGroup--25yDV>button{background:#000;border:1px solid transparent;color:#fff;cursor:pointer;padding:10px 25px;width:155px}.Header-module--toggleGroup--25yDV.Header-module--smallToggleGroup--3k8Al>button{background:#000;border:1px solid transparent;color:#fff;cursor:pointer;font-size:14px;padding:5px 15px;width:70px}.Header-module--toggleGroup--25yDV>button:hover{background:var(--color-secondary)}.Header-module--toggleGroup--25yDV>button:first-child{border-bottom-left-radius:4px;border-right:0;border-right:1px solid var(--color-light-blue);border-top-left-radius:4px}.Header-module--toggleGroup--25yDV>button:disabled{background:transparent;color:currentColor;cursor:default}.Header-module--toggleGroup--25yDV>button:last-child{border-bottom-right-radius:4px;border-left:0;border-top-right-radius:4px}.Header-module--video--4Ii6W{border:1px solid transparent;border-radius:10px;box-shadow:0 0 9px 0 #010817;cursor:pointer;display:block;transition:all .3s;width:100%}.Header-module--video--4Ii6W:hover{border:1px solid var(--color-secondary)}.Header-module--videoWrapperHide--rSaM-,.Header-module--videoWrapperShow--3R_07{margin-bottom:100px}@media (min-width:320px){.Header-module--logo--kAPp0{height:120px}}@media (min-width:768px){.Header-module--logo--kAPp0{display:none}.Header-module--head--LS_wO{height:auto}.Header-module--videoHeading--363Ps{display:none}.Header-module--desktopLogo--2dR5M{fill:#fff;display:inline-block}.Header-module--toggleGroup--25yDV{display:inline-block;margin:0 auto 50px}.Header-module--video--4Ii6W{height:400px;margin:0 auto 20px;width:700px}.Header-module--videoWrapperShow--3R_07{display:block;margin-bottom:0}.Header-module--videoWrapperHide--rSaM-{display:none;margin-bottom:0}.Header-module--logoHeading--jhvBL{margin-top:70px}}@media (min-width:1024px){.Header-module--video--4Ii6W{height:480px;width:800px}.Header-module--logoHeading--jhvBL{margin-top:50px}}@media (min-width:1280px){.Header-module--video--4Ii6W{height:600px;width:980px}}.Watcher-module--root--Qc7bh{display:none}.Watcher-module--svgWrapper--1l2_X{width:200px}.Watcher-module--watchGroup--3JlOk{display:flex;height:50px}.Watcher-module--watchGroup--3JlOk p{background:none;margin-top:5px;padding:0 0 0 50px}.Watcher-module--watchGroup--3JlOk input[type=checkbox]{-webkit-appearance:none;appearance:none;background:var(--color-secondary);border:1px solid var(--color-secondary);border-radius:2px;height:20px;margin-left:-60px;margin-top:8px;width:20px}.Watcher-module--watchGroup--3JlOk input[type=checkbox]:checked{background:#fff;border:1px solid #fff}.Watcher-module--svgWrapper--1l2_X svg{width:100%}.Watcher-module--svgWrapper--1l2_X svg path{stroke-dasharray:10;-webkit-animation:Watcher-module--dash--3rvRk 10s linear infinite normal;animation:Watcher-module--dash--3rvRk 10s linear infinite normal}@-webkit-keyframes Watcher-module--dash--3rvRk{0%{stroke-dashoffset:500}to{stroke-dashoffset:0}}@keyframes Watcher-module--dash--3rvRk{0%{stroke-dashoffset:500}to{stroke-dashoffset:0}}@media (min-width:768px){.Watcher-module--watcher--1sTFJ{display:block}.Watcher-module--root--Qc7bh{display:grid;grid-template-columns:1fr 1fr 200px;margin:40px auto;max-width:800px}.Watcher-module--svgWrapper--1l2_X{display:block;width:300px}.Watcher-module--svgWrapper--1l2_X svg{height:200px}}.CodeCompareSection-module--gridView--2Tc_D{display:flex;flex-direction:column}.CodeCompareSection-module--gridView--2Tc_D>div:first-child{order:1}.CodeCompareSection-module--gridView--2Tc_D iframe{box-shadow:0 0 20px #010817;display:none}.CodeCompareSection-module--fullScreen--9TOyk{background:none;border-bottom-left-radius:4px;border-right:none;border-color:var(--color-secondary);border-top:none;border-top-color:var(--color-secondary);color:#fff;display:none;font-size:12px;position:absolute;right:0;z-index:1}.CodeCompareSection-module--fullScreen--9TOyk:hover{background:var(--color-light-pink)}@media (min-width:1000px){.CodeCompareSection-module--gridView--2Tc_D{grid-column-gap:40px;display:grid;grid-template-columns:repeat(auto-fit,minmax(250px,1fr));margin:0 auto;max-width:1024px}.CodeCompareSection-module--gridView--2Tc_D iframe{display:block}.CodeCompareSection-module--gridView--2Tc_D>div:first-child{order:0}.CodeCompareSection-module--fullScreen--9TOyk{display:block}.CodeCompareSection-module--display--C0Vr0{display:none}}.CodePerfCompareSection-module--imgSection--3AUBW{display:flex;flex-direction:column}.CodePerfCompareSection-module--imgSection--3AUBW>img{border-radius:4px;box-shadow:0 0 8px #000;margin:20px 0;max-width:100%;object-fit:cover}.CodePerfCompareSection-module--imgSection--3AUBW ul{list-style-type:none;margin:0 15px 0 0;min-width:250px;padding-left:0}.CodePerfCompareSection-module--imgSection--3AUBW ul>li{font-size:16px;margin-left:0;padding:2px 0}.CodePerfCompareSection-module--videoWrapper--3obWJ{-webkit-overflow-scrolling:touch;display:flex;height:450px;margin:20px 0 40px;overflow-x:auto;-ms-scroll-snap-type:x mandatory;scroll-snap-type:x mandatory;width:100%}.CodePerfCompareSection-module--videoWrapper--3obWJ p{text-align:center}.CodePerfCompareSection-module--videoWrapper--3obWJ>section:first-child{order:1}.CodePerfCompareSection-module--videoWrapper--3obWJ>section{flex-shrink:0;height:100%;overflow-y:hidden;scroll-snap-align:start;width:100%}.CodePerfCompareSection-module--videoWrapper--3obWJ>section>video{border-radius:10px;height:100%;width:100%}@media (min-width:768px){.CodePerfCompareSection-module--imgSection--3AUBW{flex-direction:row;justify-content:center;max-width:80%}.CodePerfCompareSection-module--imgSection--3AUBW ul{margin-left:250px}.CodePerfCompareSection-module--videoWrapper--3obWJ>section:first-child{order:0}.CodePerfCompareSection-module--videoWrapper--3obWJ{grid-column-gap:60px;display:grid;grid-template-columns:repeat(auto-fit,minmax(10rem,1fr));height:auto;margin:40px auto;max-width:768px;overflow-y:hidden}.CodePerfCompareSection-module--videoWrapper--3obWJ>section>video{border-radius:10px;height:400px;margin-top:-44px}}@media (min-width:1024px){.CodePerfCompareSection-module--videoWrapper--3obWJ>section>video{height:450px}}.IsolateRender-module--wrapper--uPl1L{grid-gap:20px;display:grid;grid-template-columns:1fr 1fr;margin-top:20px;position:relative}.IsolateRender-module--wrapper--uPl1L>div{display:none}.IsolateRender-module--wrapper--uPl1L p{font-size:45px;font-weight:800;line-height:1.4;margin-top:160px}.IsolateRender-module--lightWrapper--1pO-R p{background:#fff}.IsolateRender-module--wrapper--uPl1L h2{font-size:14px}.IsolateRender-module--externalComponent--1B9x0{border:1px solid var(--color-secondary);border-radius:4px;font-size:14px;margin:20px 0;padding:10px 0}.IsolateRender-module--line--13-87{background:var(--color-blue);height:44%;left:50%;position:absolute;top:30%;width:1px;z-index:-1}@media (min-width:768px){.IsolateRender-module--wrapper--uPl1L{grid-gap:40px;grid-template-columns:1fr 65px 1fr}.IsolateRender-module--wrapper--uPl1L>div{display:block}.IsolateRender-module--wrapper--uPl1L h2{font-size:24px;font-weight:400;padding-bottom:10px}}.Footer-module--footer--2GJgl{font-size:.8rem;font-weight:400;margin-bottom:60px;padding:40px 0;text-align:center}.Footer-module--footer--2GJgl a{color:#fff;text-decoration:none}.Footer-module--lightFooter--Ax4kK a{color:var(--color-black)}.Footer-module--footer--2GJgl a:hover{color:var(--color-light-pink);text-decoration:none}.Footer-module--lightFooter--Ax4kK a:hover{color:var(--color-light-pink)}.Footer-module--footer--2GJgl>p{font-size:13px}.Footer-module--links--gfPmR{border-bottom:1px solid var(--color-light-pink);display:block;margin:0 auto 20px;max-width:800px;padding:0 0 10px}.Footer-module--links--gfPmR>li{display:inline-flex}.Footer-module--links--gfPmR>li>a{color:#fff;min-height:48px;min-width:48px;padding:10px 12px;text-decoration:none}.Footer-module--lightFooter--Ax4kK .Footer-module--links--gfPmR>li>a{color:var(--color-black);font-weight:500}.Footer-module--lightFooter--Ax4kK .Footer-module--links--gfPmR>li>a:hover{color:var(--color-light-pink)}.ResourcePage-module--root--112VK{margin:0 20px 40px;padding-bottom:40px}.ResourcePage-module--tagWrapper--1FtzC{display:flex;justify-content:flex-end}.ResourcePage-module--tag--1uWSS{background:#fff;border-radius:8px;color:var(--color-primary);display:block;font-size:10px;font-weight:500;margin:0;text-align:center;text-transform:uppercase;width:25px}.ResourcePage-module--contentList--102eB{list-style:none;padding:0;width:100%}.ResourcePage-module--searchFilter--1faCg{border-radius:25px;display:flex;font-size:16px;line-height:24px;margin:auto;padding:8px 20px;width:400px}.ResourcePage-module--searchFilter--1faCg:focus{border:1px solid var(--color-light-pink);cursor:default;outline:none}.ResourcePage-module--article--3a5a8{margin-bottom:15px}.ResourcePage-module--article--3a5a8 img{border:1px solid var(--color-light-blue);border-radius:4px;height:100px;object-fit:contain;width:100%}.ResourcePage-module--article--3a5a8>a{color:#fff;text-decoration:none}.ResourcePage-module--article--3a5a8>a:hover{color:var(--color-secondary)}.ResourcePage-module--article--3a5a8 h3{-webkit-line-clamp:2;font-size:18px;font-weight:500}.ResourcePage-module--article--3a5a8 h3,.ResourcePage-module--article--3a5a8 p{-webkit-box-orient:vertical;display:-webkit-box;margin:5px 0;overflow:hidden;text-overflow:ellipsis}.ResourcePage-module--article--3a5a8 p{-webkit-line-clamp:4}p.ResourcePage-module--author--3el3R{-webkit-line-clamp:1;-webkit-box-orient:vertical;display:-webkit-box;overflow:hidden;text-overflow:ellipsis}.ResourcePage-module--name--2XC7j{font-weight:600}.ResourcePage-module--contentList--102eB img{display:block;margin:0 auto;width:200px}.ResourcePage-module--contentList--102eB img:hover{border:13px solid var(--color-light-blue);opacity:.8;transition:all .3s ease-out}.ResourcePage-module--contentList--102eB>li{margin-bottom:40px;overflow:hidden;position:relative}.ResourcePage-module--contentList--102eB li>svg{fill:#091129;height:100%;position:absolute;width:100%;z-index:2}.ResourcePage-module--interests--3hwJ6{list-style:none;margin:0;padding:0}.ResourcePage-module--interests--3hwJ6>ul{border:1px solid var(--color-light-blue);display:flex;flex-direction:row;font-size:14px;margin:0;padding:8px 0;text-align:center}.ResourcePage-module--interests--3hwJ6 li{border-right:1px solid var(--color-light-blue);flex:1 1;font-size:13px;list-style:none}.ResourcePage-module--interests--3hwJ6 li:last-child{border:none}.ResourcePage-module--twitter---EOGm:hover>svg{fill:var(--color-secondary)}@media (min-width:768px){.ResourcePage-module--contentList--102eB{grid-gap:30px;display:grid;grid-template-columns:repeat(4,1fr);margin:0 auto;max-width:1280px}.ResourcePage-module--interests--3hwJ6>ul{flex-direction:column;padding:8px 20px;text-align:left}.ResourcePage-module--interests--3hwJ6>ul>li{border-right:0}.ResourcePage-module--contentList--102eB img{transition:all .3s ease-in;width:100%}}@media (min-width:1024px){.ResourcePage-module--interests--3hwJ6>ul{flex-direction:row;padding-left:0;padding-right:0;text-align:center}.ResourcePage-module--interests--3hwJ6>ul>li{border-right:1px solid var(--color-light-blue)}}.ApiGallery-module--root--2AsNc{margin:60px auto 0;max-width:768px}@media (min-width:768px){.ApiGallery-module--root--2AsNc{max-width:840px}}.ApiGallery-module--gallery--1kcSl{grid-gap:25px;display:grid;grid-template-columns:1fr;list-style:none;margin:20px;padding:0}@media (min-width:768px){.ApiGallery-module--gallery--1kcSl{grid-gap:25px;grid-template-columns:repeat(3,1fr);margin:60px auto;padding:0 20px}}@media (min-width:1024px){.ApiGallery-module--gallery--1kcSl{max-width:1024px}}.ApiGallery-module--gallery--1kcSl li{border:1px solid var(--color-light-blue);padding-bottom:30px;position:relative;transition:all .2s}.ApiGallery-module--gallery--1kcSl li:hover{border:1px solid var(--color-secondary);box-shadow:2px 2px 0 4px #000;-webkit-transform:translate(-2px,-2px);transform:translate(-2px,-2px)}.ApiGallery-module--gallery--1kcSl li a{align-items:flex-end;bottom:0;display:flex;font-size:14px;justify-content:flex-end;left:0;padding:12px 20px 12px 80px;position:absolute;right:0;top:0}.ApiGallery-module--gallery--1kcSl h3{background:var(--color-button-blue);border-bottom:1px solid var(--color-light-blue);font-size:18px;font-weight:400;letter-spacing:1px;margin:0;padding:13px 20px;text-shadow:2px 2px #000}.ApiGallery-module--gallery--1kcSl h3 code{letter-spacing:-1px;margin-right:5px}.ApiGallery-module--gallery--1kcSl p{font-size:14px;margin:20px}.ApiGallery-module--versionControl--8jKNb{padding-right:20px;text-align:right}.ApiGallery-module--versionControl--8jKNb>div{display:inline-block}.ApiGallery-module--versionControl--8jKNb>p{color:var(--color-light-grey);display:inline-block;font-size:14px;margin-right:20px}.DevToolFeaturesList-module--featuresContent--XyGtv{text-align:center}.DevToolFeaturesList-module--featuresContent--XyGtv h3{font-size:20px;font-weight:400;margin-top:10px}.DevToolFeaturesList-module--featuresContent--XyGtv svg{fill:#fff;display:block;height:60px;margin:0 auto;width:50px}.DevToolFeaturesList-module--lightFeaturesContent--DnrAe svg{fill:var(--color-black)}.DevToolFeaturesList-module--featuresContent--XyGtv>article{padding-bottom:30px}.DevToolFeaturesList-module--featuresContent--XyGtv>article>div{-webkit-transform:scale(0);transform:scale(0)}.DevToolFeaturesList-module--features--2M0Qq{margin-top:-60px}.DevToolFeaturesList-module--features--2M0Qq>h2{margin-bottom:30px}@media (min-width:768px){.DevToolFeaturesList-module--featuresContent--XyGtv h3{font-size:22px}.DevToolFeaturesList-module--features--2M0Qq>h2{margin:0 auto 20px;max-width:450px}.DevToolFeaturesList-module--features--2M0Qq{margin-top:60px}.DevToolFeaturesList-module--featuresContent--XyGtv{grid-column-gap:40px;display:grid;grid-template-columns:repeat(3,1fr);margin:20px auto 30px;max-width:800px}}.DevTools-module--container--o8ZZ-{display:grid}.DevTools-module--devToolImg--2m-BE{border-radius:5px;cursor:not-allowed;display:block;height:230px;margin:30px auto 80px}.DevTools-module--devTool--2fony ::-webkit-scrollbar-track{background:inherit}.DevTools-module--devTool--2fony ::-webkit-scrollbar-thumb{background:grey}.DevTools-module--devTool--2fony ::-webkit-scrollbar-thumb:hover{background:#000}.DevTools-module--demo--1BTJK{grid-gap:30px;display:grid;margin:0 auto;max-width:768px}.DevTools-module--demo--1BTJK>div:first-child{order:2}@media (min-width:768px){.DevTools-module--devToolImg--2m-BE{border-radius:8px;display:block;height:auto;margin:50px auto 0;max-width:600px;min-height:420px}.DevTools-module--demo--1BTJK{grid-gap:30px;display:grid;grid-template-columns:1fr 1fr;margin:0 auto;max-width:768px}.DevTools-module--demo--1BTJK>div:first-child{order:0}}@media (min-width:1024px){.DevTools-module--devTool--2fony{display:block}.DevTools-module--devToolImg--2m-BE{max-width:800px}}.SortableContainer-module--list--35F0F{background:var(--color-primary);border:1px solid var(--color-light-blue);border-radius:4px;color:#fff;cursor:move;list-style:none;margin-bottom:10px;padding:14px 14px 14px 50px;position:relative}.SortableContainer-module--list--35F0F>svg{fill:#fff;display:inline-block;left:15px;position:absolute;top:17px;width:20px}.SortableContainer-module--editPanel--2cJSC{float:right}.SortableContainer-module--editPanel--2cJSC>button{background:var(--color-light-blue);border:1px solid transparent;color:#fff;cursor:pointer;font-size:14px;letter-spacing:1px;padding:1px 8px;position:relative;text-transform:uppercase;top:-2px}.SortableContainer-module--editPanel--2cJSC>button:hover{background:var(--color-primary);border:1px solid var(--color-secondary)}.SortableContainer-module--editPanel--2cJSC>button:first-child{margin-right:14px}.SortableContainer-module--sortableWrapper--1Ltbr{margin-top:30px}.SortableContainer-module--sortableWrapper--1Ltbr>ul{margin-left:0;padding-left:0}.Popup-module--button--2tjfi,.Popup-module--icon--1sbzO,.Popup-module--iconStyle--2u728{align-items:center;border:none;border-radius:50%;display:inline-flex;font-size:15px;height:18px;justify-content:center;line-height:1;margin-left:10px;width:18px}.Popup-module--icon--1sbzO{border:1px solid #fff;margin-left:0;margin-right:5px}.Popup-module--root--1RSJV{font-weight:700;position:relative}.Popup-module--root--1RSJV>span{display:inline-block;font-size:14px!important;font-weight:400;margin-left:10px;overflow:hidden;position:relative;top:5px}.Popup-module--root--1RSJV>span>span{display:inline-block;font-family:sans-serif;position:relative}.Popup-module--button--2tjfi{cursor:pointer}.Popup-module--button--2tjfi:hover{background:var(--color-light-pink);color:#fff}.VideoList-module--list--3d5iw{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.VideoList-module--list--3d5iw>span{border:1px solid #fff;margin-right:20px}.VideoList-module--list--3d5iw:hover>span{color:var(--color-light-pink);transition:.3s}.VideoList-module--list--3d5iw a{text-decoration:none}.VideoList-module--list--3d5iw:hover a{text-decoration:underline}.ApiPage-module--mobileTypeText--30IdC{color:var(--color-light-pink);display:block;font-family:monospace;font-size:15px;font-weight:400;margin-top:10px}.ApiPage-module--quickSelect--27FNB{margin:0 auto;max-width:320px;position:relative}.ApiPage-module--quickSelect--27FNB:after{content:"▼";font-size:15px;pointer-events:none;position:absolute;right:17%;top:12px}.ApiPage-module--quickSelect--27FNB>select{-webkit-appearance:none;appearance:none;background:none;border:1px solid var(--color-light-blue);border-radius:4px;color:#fff;display:block;font-size:2rem;font-weight:lighter;margin:.67em auto 20px;max-width:240px;padding:10px 30px;position:relative;text-align:center;text-align-last:center}.ApiPage-module--lightQuickSelect--AeL2v.ApiPage-module--quickSelect--27FNB>select{color:#000}.ApiPage-module--versionToggle--3aWK8{position:absolute;right:20px}@media (min-width:768px){.ApiPage-module--hiddenMenu--1e0XE>h1{display:block}.ApiPage-module--hiddenMenu--1e0XE>div{display:none}}.BuilderPage-module--root--30ma9{-webkit-overflow-scrolling:touch;box-sizing:border-box;height:100vh;left:0;position:fixed;top:0;width:100%;z-index:11}.BuilderPage-module--pageWrapper--1Cw2r{grid-column-gap:60px;display:grid;grid-template-columns:repeat(auto-fit,minmax(15rem,1fr));margin:0 auto 100px;max-width:2000px;overflow:hidden;padding:0 20px 100px}.BuilderPage-module--pageWrapper--1Cw2r>section:first-child{margin-top:50px;order:3}.BuilderPage-module--pageWrapper--1Cw2r>form:nth-child(2){order:1}.BuilderPage-module--pageWrapper--1Cw2r>section:nth-child(3){order:2}.BuilderPage-module--form--2MIRV input,.BuilderPage-module--form--2MIRV select{border-radius:4px;box-sizing:border-box;display:block;font-size:16px;margin-bottom:10px;padding:6px 10px;width:100%}.BuilderPage-module--form--2MIRV input:hover,.BuilderPage-module--form--2MIRV select:hover{border:1px solid var(--color-light-pink)}.BuilderPage-module--form--2MIRV select:not([multiple]){height:40px}.BuilderPage-module--form--2MIRV input.BuilderPage-module--form-error--1XNP4{border:1px solid #bf1650}.BuilderPage-module--form--2MIRV input[type=checkbox]{display:inline-block;margin-right:10px;width:auto}.BuilderPage-module--form--2MIRV label{display:block;line-height:2;margin-bottom:13px;margin-top:20px;text-align:left}.BuilderPage-module--form--2MIRV fieldset{border:1px solid var(--color-light-blue);border-radius:4px}.BuilderPage-module--closeButton--3TZPt{background:var(--color-primary);border:1px solid #fff;border-radius:4px;color:#fff;cursor:pointer;display:flex;font-size:25px;height:50px;justify-content:center;position:absolute;right:30px;top:20px;width:50px;z-index:5}.BuilderPage-module--closeButton--3TZPt:hover{border:1px solid var(--color-secondary)}@media (min-width:768px){.BuilderPage-module--pageWrapper--1Cw2r>section:first-child{margin-top:0;order:1}.BuilderPage-module--pageWrapper--1Cw2r>form:nth-child(2){order:2}.BuilderPage-module--pageWrapper--1Cw2r>section:nth-child(3){order:3}.BuilderPage-module--closeButton--3TZPt{align-items:center;display:flex;justify-content:center}}.BuilderPage-module--buttonWrapper--2RYc_{display:flex;position:absolute;right:5px;top:10px}.BuilderPage-module--button--lSrFP{align-items:center;border:none;border-radius:0;color:#fff;cursor:pointer;display:none;font-size:13px;height:34px;margin:0 3px;padding:0 10px;right:20px;text-transform:uppercase;top:10px;z-index:1}.BuilderPage-module--button--lSrFP:hover{background:var(--color-secondary);color:#fff}@media (min-width:768px){.BuilderPage-module--button--lSrFP{display:flex}}.BuilderPage-module--copyButton--2uOjN{background:var(--color-light-blue);border:1px solid transparent}.BuilderPage-module--active--JgbuO,.BuilderPage-module--copyButton--2uOjN:hover{background:none;border:1px solid var(--color-secondary);color:#fff}.BuilderPage-module--active--JgbuO,.BuilderPage-module--copyButton--2uOjN:hover span{background:var(--color-primary)}.BuilderPage-module--wrapper--29W5S pre{line-height:1.5!important}.BuilderPage-module--wrapper--29W5S pre code{display:none}.BuilderPage-module--wrapper--29W5S pre code.BuilderPage-module--showCode--2YHPc{display:block}.FeatureList-module--featuresContent--3bq0c{text-align:center}.FeatureList-module--featuresContent--3bq0c h3{font-size:20px;font-weight:500;margin-top:10px}.FeatureList-module--featuresContent--3bq0c svg{display:block;height:60px;margin:0 auto;width:50px}.FeatureList-module--lightFeaturesContent--FnFsl svg{fill:var(--color-black)}.FeatureList-module--featuresContent--3bq0c>article{padding-bottom:30px}.FeatureList-module--featuresContent--3bq0c>article>div{-webkit-transform:scale(0);transform:scale(0)}.FeatureList-module--features--YwynT{margin-top:-60px}.FeatureList-module--features--YwynT>h2{margin-bottom:30px}@media (min-width:768px){.FeatureList-module--featuresContent--3bq0c h3{font-size:22px}.FeatureList-module--features--YwynT>h2{margin:0 auto 20px;max-width:450px}.FeatureList-module--features--YwynT{margin-bottom:60px;margin-top:60px}.FeatureList-module--featuresContent--3bq0c{grid-column-gap:30px;display:grid;grid-template-columns:repeat(3,1fr);margin:40px auto 30px;max-width:1024px}}@media (min-width:1280px){.FeatureList-module--featuresContent--3bq0c{grid-column-gap:25px;grid-template-columns:repeat(6,1fr);max-width:1480px}.FeatureList-module--featuresContent--3bq0c>article{padding-bottom:0}}.HomePage-module--root--2TxQs{padding:0 20px 50px;position:relative}.HomePage-module--feedback--1vWOg{margin-top:40px}.HomePage-module--feedback--1vWOg>div{border-radius:15px;margin-bottom:20px}.HomePage-module--feedback--1vWOg>div>svg{margin:0 auto;width:45px}.HomePage-module--feedback--1vWOg>div>p{font-size:15px;padding:20px;text-align:left}@media (min-width:768px){.HomePage-module--feedback--1vWOg{grid-gap:50px;display:grid;grid-template-columns:repeat(3,1fr)}.HomePage-module--feedback--1vWOg>div{margin-bottom:0}}@media (min-width:1024px){.HomePage-module--root--2TxQs{padding:0 50px}}
useFieldArray | React Hook Form - Simple React forms validation Skip to content
useFieldArray React hooks for Field Array
useFieldArray:({ control?: Control, name: string, keyName?: string = 'id' }) => object
Custom hook for working with uncontrolled Field Arrays (dynamic inputs). The motivation is to provide better user experience and form performance. You can watch this short video to compare controlled vs uncontrolled Field Array.
Props Name Type Required Description name
string
✓ Name of the field. Important: make sure name is in object shape: name=test.0.name
as we don't support flat arrays.
control
Object
control
object provided by useForm
. It's optional if you are using FormContext.keyName
string = 'id'
field array key
value, default to "id", you can change the key name. shouldUnregister
boolean = false
Field Array will be unregistered after unmount.
Copy
function Test() {
const { control, register } = useForm();
const { fields, append, prepend, remove, swap, move, insert } = useFieldArray({
control, // control props comes from useForm (optional: if you are using FormContext)
name: "test", // unique name for your Field Array
// keyName: "id", default to "id", you can change the key name
});
return (
{fields.map((field, index) => (
<input
key={field.id} // important to include key with field's id
{...register(`test.${index}.value`)}
defaultValue={field.value} // make sure to include defaultValue
/>
))}
);
}
Rules The field.id
(and not index
) must be added as the component key to prevent re-renders breaking the fields:
// ✅ correct:
{fields.map((field, index) => (
<div key={field.id}>
<input ... />
</div>
))}
// ✅ correct:
{fields.map((field, index) => <input key={field.id} ... />)}
// ❌ incorrect:
{fields.map((field, index) => <input key={index} ... />)}
defaultValue
must be set for all inputs. Supplied defaultValues
in the useForm
hook will prepare the fields
object with default value.
You can not call actions one after another. Actions need to be triggered per render.
// ❌ The following is not correct
handleChange={() => {
if (fields.length === 2) {
remove(0);
}
append({ test: 'test' });
}}
// ✅ The following is correct and second action is triggered after next render
handleChange={() => {
append({ test: 'test' });
}}
React.useEffect(() => {
if (fields.length === 2) {
remove(0);
}
}, [fields])
Each useFieldArray
is unique and has its own state update, which means you should not have multiple useFieldArray with the same name
.
Each input name needs to be unique, if you need to build checkbox or radio with the same name then use it with useController
or controller
.
Does not support flat field array.
When you append, prepend, insert and update the field array, the obj can't be empty object
rather need to supply all your input's defaultValues.
append(); ❌
append({}); ❌
append({ firstName: 'bill', lastName: 'luo' }); ✅
TypeScript when register input name
, you will have to cast them as const
<input key={field.id} {...register(`test.${index}.test` as const)} defaultValue={field.test} />
we do not support circular reference. Refer to this this Github issue for more detail.
for nested field array, you will have to cast the field array by its name.
const { fields } = useFieldArray({ name: `test.${index}.keyValue` as 'test.0.keyValue' });
Return Name Type Description fields
object & { id: string }
This object
contains the defaultValue
and key
for all your inputs. It's important to assign defaultValue
to the inputs.Important: Because each input can be uncontrolled, id
is required with mapped components to help React to identify which items have changed, are added, or are removed.
{fields.map((data, index) =>
<input
key={data.id}
defaultValue={data.value}
name={`data.${index}.value`}
/>;
);}
append
(obj: object | object[], { shouldFocus?: boolean; focusIndex?: number; focusName?: string; }) => void
Append input/inputs to the end of your fields and focus. The input value will be registered during this action.
prepend
(obj: object | object[], { shouldFocus?: boolean; focusIndex?: number; focusName?: string; }) => void
Prepend input/inputs to the start of your fields and focus. The input value will be registered during this action.
insert
(index: number, value: object | object[], { shouldFocus?: boolean; focusIndex?: number; focusName?: string; }) => void
Insert input/inputs at particular position and focus.
swap
(from: number, to: number) => void
Swap input/inputs position. move
(from: number, to: number) => void
Move input/inputs to another position. update
(index?: number, obj: object) => void
Update input/inputs at particular position. remove
(index?: number | number[]) => void
Remove input/inputs at particular position, or remove all when no index provided.
useFieldArray conditional Field Array Focus Name/index
import React from "react";
import { useForm, useFieldArray } from "react-hook-form";
function App() {
const { register, control, handleSubmit, reset, trigger, setError } = useForm({
// defaultValues: {}; you can populate the fields by this attribute
});
const { fields, append, prepend, remove, swap, move, insert } = useFieldArray({
control,
name: "test"
});
return (
<form onSubmit={handleSubmit(data => console.log(data))}>
<ul>
{fields.map((item, index) => (
<li key={item.id}>
<input
{...register(`test.${index}.firstName`)}
defaultValue={item.firstName} // make sure to set up defaultValue
/>
<Controller
render={({ field }) => <input {...field} />}
name={`test.${index}.lastName`}
control={control}
defaultValue={item.lastName} // make sure to set up defaultValue
/>
<button type="button" onClick={() => remove(index)}>Delete</button>
</li>
))}
</ul>
<button
type="button"
onClick={() => append({ firstName: "appendBill", lastName: "appendLuo" })}
>
append
</button>
<input type="submit" />
</form>
);
}
import * as React from "react";
import { useForm, useFieldArray, useWatch, Control } from "react-hook-form";
type FormValues = {
cart: {
name: string;
price: number;
quantity: number;
}[];
};
const Total = ({ control }: { control: Control<FormValues> }) => {
const formValues = useWatch({
name: "cart",
control
});
const total = formValues.reduce(
(acc, current) => acc + (current.price || 0) * (current.quantity || 0),
0
);
return <p>Total Amount: {total}</p>;
};
export default function App() {
const {
register,
control,
handleSubmit,
formState: { errors }
} = useForm<FormValues>({
defaultValues: {
cart: [{ name: "test", quantity: 1, price: 23 }]
},
mode: "onBlur"
});
const { fields, append, remove } = useFieldArray({
name: "cart",
control
});
const onSubmit = (data: FormValues) => console.log(data);
return (
<div>
<form onSubmit={handleSubmit(onSubmit)}>
{fields.map((field, index) => {
return (
<div key={field.id}>
<section className={"section"} key={field.id}>
<input
placeholder="name"
{...register(`cart.${index}.name` as const, {
required: true
})}
className={errors?.cart?.[index]?.name ? "error" : ""}
/>
<input
placeholder="quantity"
type="number"
{...register(`cart.${index}.quantity` as const, {
valueAsNumber: true,
required: true
})}
className={errors?.cart?.[index]?.quantity ? "error" : ""}
/>
<input
placeholder="value"
type="number"
{...register(`cart.${index}.price` as const, {
valueAsNumber: true,
required: true
})}
className={errors?.cart?.[index]?.price ? "error" : ""}
/>
<button type="button" onClick={() => remove(index)}>
DELETE
</button>
</section>
</div>
);
})}
<Total control={control} />
<button
type="button"
onClick={() =>
append({
name: "",
quantity: 0,
price: 0
})
}
>
APPEND
</button>
<input type="submit" />
</form>
</div>
);
}
import React from 'react';
import { useForm, useWatch, useFieldArray, Control } from 'react-hook-form';
const ConditionField = ({
control,
index,
register,
}: {
control: Control;
index: number;
}) => {
const output = useWatch<any>({
name: 'data',
control,
defaultValue: 'yay! I am watching you :)',
});
return (
<>
{output[index]?.name === "bill" && (
<input {...register(`data[${index}].conditional`)} />
)}
<input
{...register(`data[${index}].easyConditional`)}
style={{ display: output[index]?.name === "bill" ? "block" : "none" }}
/>
</>
);
};
const UseFieldArrayUnregister: React.FC = () => {
type FormValues = {
data: { name: string }[];
};
const { control, handleSubmit, register } = useForm<FormValues>({
defaultValues: {
data: [{ name: 'test' }, { name: 'test1' }, { name: 'test2' }],
},
mode: 'onSubmit',
shouldUnregister: false,
});
const { fields } = useFieldArray({
control,
name: 'data',
});
const onSubmit = (data: FormValues) => console.log(data);
return (
<form onSubmit={handleSubmit(onSubmit)}>
{fields.map((data, index) => (
<>
<input
defaultValue={data.name}
{...register(`data[${index}].name`)}
/>
<ConditionField control={control} register={register} index={index} />
</>
))}
<input type="submit" />
</form>
);
};
Copy
import React from 'react';
import { useForm, useFieldArray } from 'react-hook-form';
const App = () => {
const { register, control } = useForm<{
test: { value: string }[];
}>({
defaultValues: {
test: [{ value: '1' }, { value: '2' }],
},
});
const { fields, prepend, append } = useFieldArray({
name: 'test',
control,
});
return (
<form>
{fields.map((field, i) => (
<input key={field.id} {...register(`test.${i}.value` as const)} />
))}
<button
type="button"
onClick={() => prepend({ value: '' }, { focusIndex: 1 })}
>
prepend
</button>
<button
type="button"
onClick={() => append({ value: '' }, { focusName: 'test.0.value' })}
>
append
</button>
</form>
);
};
Tips Custom Register You can also register
inputs at Controller
without the actual input. This makes useFieldArray
quick flexible to use with complex data structure or the actual data is not stored inside an input.
import * as React from "react";
import { useForm, useFieldArray, Controller, useWatch } from "react-hook-form";
const ConditionalInput = ({ control, index, field }) => {
const value = useWatch({
name: "test",
control
});
return (
<Controller
control={control}
name={`test.${index}.firstName`}
render={({ field }) =>
value?.[index]?.checkbox === "on" ? <input {...field} /> : null
}
defaultValue={field.firstName}
/>
);
};
function App() {
const { handleSubmit, control, register } = useForm();
const { fields, append, prepend } = useFieldArray({
control,
name: "test"
});
const onSubmit = (data) => console.log(data);
return (
<form onSubmit={handleSubmit(onSubmit)}>
{fields.map((field, index) => (
<section key={field.id}>
<input
type="checkbox"
value="on"
{...register(`test.${index}.checkbox`)}
defaultChecked={field.checked}
/>
<ConditionalInput {...{ control, index, field }} />
</section>
))}
<button
type="button"
onClick={() => append({ firstName: "append value" }) }
>
append
</button>
<input type="submit" />
</form>
);
}
Controlled Field Array There will be cases where you want to control the entire field array, which means each onChange reflects on the fields
object. You can achieve this by merge with useWatch
or watch
's result.
import * as React from "react";
import { useForm, useFieldArray } from "react-hook-form";
export default function App() {
const { register, handleSubmit, control, watch } = useForm<FormValues>();
const { fields, append } = useFieldArray({
control,
name: "fieldArray"
});
const watchFieldArray = watch("fieldArray");
const controlledFields = fields.map((field, index) => {
return {
...field,
...watchFieldArray[index]
};
});
return (
<form>
{controlledFields.map((field, index) => {
return <input {...register(`fieldArray.${index}.name` as const)} />;
})}
<button
type="button"
onClick={() =>
append({
name: "bill"
})
}
>
Append
</button>
</form>
);
}
Conditional inputs useFieldArray
is uncontrolled by default, which meansdefaultValue
is rendered during input's mounting. This is different from the controlled form, which the local state is keeping updated during user interaction's onChange
. When inputs get unmounted and remounted, you want to read what's in the current form values from getValue
function. For individual input, you can safely use useWatch
hook to retain input value as well.
import React from "react";
import { useForm, useFieldArray, Controller, useWatch } from "react-hook-form";
const Input = ({ name, control, register, index }) => {
const value = useWatch({
control,
name
});
return <input {...register(`test.${index}.age`)} defaultValue={value} />;
};
function App() {
const [show, setShow] = React.useState(true);
const { register, control, getValues, handleSubmit } = useForm({
defaultValues: {
test: [{ firstName: "Bill", lastName: "Luo", age: "2" }]
}
});
const { fields, remove } = useFieldArray({
control,
name: "test"
});
const onSubmit = (data) => console.log("data", data);
return (
<form onSubmit={handleSubmit(onSubmit)}>
{show && (
<ul>
{fields.map((item, index) => {
return (
<li key={item.id}>
<input
defaultValue={getValues(`test.${index}.firstName`)}
{...register(`test.${index}.firstName`)}
/>
<Input
register={register}
control={control}
index={index}
name={`test.${index}.age`}
/>
</li>
);
})}
</ul>
)}
<section>
<button
type="button"
onClick={() => {
setShow(!show);
}}
>
Hide
</button>
</section>
<input type="submit" />
</form>
);
}