22 BarElement , CategoryScale , Chart as ChartJS , Filler , Legend , LinearScale , LineElement , PointElement , Tooltip
33} from "chart.js"
44import Head from "next/head"
5- import { EffectCallback , useEffect , useState } from "react"
5+ import { EffectCallback , useEffect , useState , useMemo } from "react"
66import { Bar , Line } from "react-chartjs-2"
77import FormattedLink from "../../components/FormattedLink"
88import Main from "../../components/Main"
@@ -92,12 +92,15 @@ export default function GachaCalc({ location }: { location: string }) {
9292 const [ guaranteed , setGuaranteed ] = useState ( false )
9393 const [ guaranteedPity , setGuaranteedPity ] = useState ( 0 )
9494
95- const [ calculated , setCalculated ] = useState ( [ [ ] ] as ReducedSim [ ] [ ] )
96-
9795 const [ gachaName , setGacha ] = useState ( Object . values ( gachas ) . map ( g => g . bannerName ) [ 0 ] )
9896
9997 const banner = Object . values ( gachas ) . find ( x => x . bannerName == gachaName ) ?? Object . values ( gachas ) [ 0 ]
10098
99+ const calculated = useMemo (
100+ ( ) => calcSimsRegular ( current , pity , pulls , guaranteed , guaranteedPity , banner ) ,
101+ [ current , pity , pulls , guaranteed , guaranteedPity , banner ]
102+ )
103+
101104 function delayed ( f : EffectCallback ) {
102105 const timeout = setTimeout ( ( ) => {
103106 f ( )
@@ -111,10 +114,6 @@ export default function GachaCalc({ location }: { location: string }) {
111114 useEffect ( ( ) => delayed ( ( ) => { if ( current > banner . maxConst ) setCurrent ( banner . maxConst ) } ) , [ banner , current ] )
112115 useEffect ( ( ) => delayed ( ( ) => { if ( current < banner . minConst ) setCurrent ( banner . minConst ) } ) , [ current , banner ] )
113116
114- useEffect (
115- ( ) => setCalculated ( calcSimsRegular ( current , pity , pulls , guaranteed , guaranteedPity , banner ) ) ,
116- [ current , pity , pulls , guaranteed , guaranteedPity , banner ]
117- )
118117 const consts = [ ]
119118 for ( let i = current ; i <= banner . maxConst ; i ++ ) consts . push ( i )
120119
0 commit comments