diff --git a/packages/apps/src/Endpoints/index.tsx b/packages/apps/src/Endpoints/index.tsx index b3a150e46f..5bf4cc285b 100644 --- a/packages/apps/src/Endpoints/index.tsx +++ b/packages/apps/src/Endpoints/index.tsx @@ -121,10 +121,10 @@ function loadAffinities (groups: Group[]): Record { function Endpoints ({ className = '', offset, onClose }: Props): React.ReactElement { const { t } = useTranslation(); const linkOptions = createWsEndpoints(t); - const [groups, setGroups] = useState(combineEndpoints(linkOptions)); - const [{ apiUrl, groupIndex, hasUrlChanged, isUrlValid }, setApiUrl] = useState(extractUrlState(settings.get().apiUrl, groups)); - const [storedCustomEndpoints, setStoredCustomEndpoints] = useState(getCustomEndpoints()); - const [affinities, setAffinities] = useState(loadAffinities(groups)); + const [groups, setGroups] = useState(() => combineEndpoints(linkOptions)); + const [{ apiUrl, groupIndex, hasUrlChanged, isUrlValid }, setApiUrl] = useState(() => extractUrlState(settings.get().apiUrl, groups)); + const [storedCustomEndpoints, setStoredCustomEndpoints] = useState(() => getCustomEndpoints()); + const [affinities, setAffinities] = useState(() => loadAffinities(groups)); const isKnownUrl = useMemo(() => { let result = false; diff --git a/packages/apps/src/Root.tsx b/packages/apps/src/Root.tsx index e6f1b8a00d..784d95a86b 100644 --- a/packages/apps/src/Root.tsx +++ b/packages/apps/src/Root.tsx @@ -28,7 +28,7 @@ function createTheme ({ uiTheme }: { uiTheme: string }): ThemeDef { } function Root ({ store }: Props): React.ReactElement { - const [theme, setTheme] = useState(createTheme(settings)); + const [theme, setTheme] = useState(() => createTheme(settings)); useEffect((): void => { settings.on('change', (settings) => setTheme(createTheme(settings))); diff --git a/packages/page-accounts/src/Sidebar/RegistrarJudgement.tsx b/packages/page-accounts/src/Sidebar/RegistrarJudgement.tsx index 0b2bac8fee..89bc6c4608 100644 --- a/packages/page-accounts/src/Sidebar/RegistrarJudgement.tsx +++ b/packages/page-accounts/src/Sidebar/RegistrarJudgement.tsx @@ -26,7 +26,7 @@ const JUDGEMENT_ENUM = [ function RegistrarJudgement ({ address, registrars, toggleJudgement }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const [addresses] = useState(registrars.map(({ address }) => address)); + const [addresses] = useState(() => registrars.map(({ address }) => address)); const [judgementAccountId, setJudgementAccountId] = useState(null); const [judgementEnum, setJudgementEnum] = useState(2); // Reasonable const [registrarIndex, setRegistrarIndex] = useState(-1); diff --git a/packages/page-accounts/src/modals/Create.tsx b/packages/page-accounts/src/modals/Create.tsx index 243b4dacc9..8d4ac0323d 100644 --- a/packages/page-accounts/src/modals/Create.tsx +++ b/packages/page-accounts/src/modals/Create.tsx @@ -185,7 +185,7 @@ function createAccount (suri: string, pairType: KeypairType, { genesisHash, name function Create ({ className = '', onClose, onStatusChange, seed: propsSeed, type: propsType }: Props): React.ReactElement { const { t } = useTranslation(); const { api, isDevelopment, isEthereum } = useApi(); - const [{ address, derivePath, deriveValidation, isSeedValid, pairType, seed, seedType }, setAddress] = useState(generateSeed(propsSeed, '', propsSeed ? 'raw' : 'bip', isEthereum ? 'ethereum' : propsType)); + const [{ address, derivePath, deriveValidation, isSeedValid, pairType, seed, seedType }, setAddress] = useState(() => generateSeed(propsSeed, '', propsSeed ? 'raw' : 'bip', isEthereum ? 'ethereum' : propsType)); const [isMnemonicSaved, setIsMnemonicSaved] = useState(false); const [step, setStep] = useState(1); const [isBusy, setIsBusy] = useState(false); diff --git a/packages/page-accounts/src/modals/Derive.tsx b/packages/page-accounts/src/modals/Derive.tsx index 6821f6609b..4cc336f252 100644 --- a/packages/page-accounts/src/modals/Derive.tsx +++ b/packages/page-accounts/src/modals/Derive.tsx @@ -83,7 +83,7 @@ function Derive ({ className = '', from, onClose }: Props): React.ReactElement { const { t } = useTranslation(); const { api, isDevelopment } = useApi(); const { queueAction } = useContext(StatusContext); - const [source] = useState(keyring.getPair(from)); + const [source] = useState(() => keyring.getPair(from)); const [isBusy, setIsBusy] = useState(false); const [{ address, deriveError }, setDerive] = useState({ address: null, deriveError: null }); const [isConfirmationOpen, toggleConfirmation] = useToggle(); diff --git a/packages/page-accounts/src/modals/IdentityMain.tsx b/packages/page-accounts/src/modals/IdentityMain.tsx index 316ebd154e..b3cfd3258b 100644 --- a/packages/page-accounts/src/modals/IdentityMain.tsx +++ b/packages/page-accounts/src/modals/IdentityMain.tsx @@ -80,17 +80,13 @@ function IdentityMain ({ address, className = '', onClose }: Props): React.React const identityOpt = useCall>(api.query.identity.identityOf, [address]); const [{ info, okAll, okDisplay, okEmail, okLegal, okRiot, okTwitter, okWeb }, setInfo] = useState({ info: {}, okAll: false }); const [hasEmail, setHasEmail] = useState(false); - // const [hasImg, setHasImg] = useState(false); const [hasLegal, setHasLegal] = useState(false); - // const [hasPgp, setHasPgp] = useState(false); const [hasRiot, setHasRiot] = useState(false); const [hasTwitter, setHasTwitter] = useState(false); const [hasWeb, setHasWeb] = useState(false); - const [valDisplay, setValDisplay] = useState((getAddressMeta(address).name || '').replace(/\(.*\)/, '').trim()); + const [valDisplay, setValDisplay] = useState(() => (getAddressMeta(address).name || '').replace(/\(.*\)/, '').trim()); const [valEmail, setValEmail] = useState(''); - // const [{ errImg, valImg }, setValImg] = useState<{ errImg: boolean; valImg: string }>({ errImg: true, valImg: '' }); const [valLegal, setValLegal] = useState(''); - // const [{ errPgp, valPgp }, setValPgp] = useState<{ errPgp: boolean; valPgp: string }>({ errPgp: true, valPgp: '' }); const [valRiot, setValRiot] = useState(''); const [valTwitter, setValTwitter] = useState(''); const [valWeb, setValWeb] = useState(''); @@ -135,8 +131,6 @@ function IdentityMain ({ address, className = '', onClose }: Props): React.React riot: { [okRiot && hasRiot ? 'raw' : 'none']: okRiot && hasRiot ? valRiot : null }, twitter: { [okTwitter && hasTwitter ? 'raw' : 'none']: okTwitter && hasTwitter ? valTwitter : null }, web: { [okWeb && hasWeb ? 'raw' : 'none']: okWeb && hasWeb ? valWeb : null } - // image: { [hasImg ? 'sha256' : 'none']: hasImg ? valImg : null }, - // pgpFingerprint: hasPgp ? valPgp : null }, okAll: okDisplay && okEmail && okLegal && okRiot && okTwitter && okWeb, okDisplay, @@ -146,7 +140,6 @@ function IdentityMain ({ address, className = '', onClose }: Props): React.React okTwitter, okWeb }); - // errImg, errPgp, hasImg, hasPgp, valImg, valPgp, }, [hasEmail, hasLegal, hasRiot, hasTwitter, hasWeb, valDisplay, valEmail, valLegal, valRiot, valTwitter, valWeb]); return ( diff --git a/packages/page-calendar/src/index.tsx b/packages/page-calendar/src/index.tsx index 143ef14f3c..543c8beffb 100644 --- a/packages/page-calendar/src/index.tsx +++ b/packages/page-calendar/src/index.tsx @@ -26,8 +26,8 @@ const NOW_INC = 30 * 1000; function CalendarApp ({ basePath, className }: Props): React.ReactElement { const { t } = useTranslation(); const scheduled = useScheduled(); - const [now, setNow] = useState(new Date()); - const [dateState, setDateState] = useState(getDateState(now, now)); + const [now, setNow] = useState(() => new Date()); + const [dateState, setDateState] = useState(() => getDateState(now, now)); const [allEventsView, setAllEventsView] = useState(false); const itemsRef = useRef([{ diff --git a/packages/page-contracts/src/Contracts/Deploy.tsx b/packages/page-contracts/src/Contracts/Deploy.tsx index e04d6cd095..babc52873a 100644 --- a/packages/page-contracts/src/Contracts/Deploy.tsx +++ b/packages/page-contracts/src/Contracts/Deploy.tsx @@ -37,7 +37,7 @@ function Deploy ({ codeHash, constructorIndex = 0, onClose, setConstructorIndex const [params, setParams] = useState([]); const [accountId, isAccountIdValid, setAccountId] = useFormField(null); const [endowment, isEndowmentValid, setEndowment] = useNonZeroBn(new BN(ENDOWMENT)); - const [salt, setSalt] = useState(randomAsHex()); + const [salt, setSalt] = useState(() => randomAsHex()); const [withSalt, setWithSalt] = useState(false); useEffect((): void => { diff --git a/packages/page-contracts/src/Contracts/index.tsx b/packages/page-contracts/src/Contracts/index.tsx index e8b3a1caf9..dc8e27620b 100644 --- a/packages/page-contracts/src/Contracts/index.tsx +++ b/packages/page-contracts/src/Contracts/index.tsx @@ -29,8 +29,8 @@ function Contracts ({ className = '' }: Props): React.ReactElement { const [isDeployOpen, toggleDeploy, setIsDeployOpen] = useToggle(); const [isHashOpen, toggleHash] = useToggle(); const [isUploadOpen, toggleUpload] = useToggle(); - const [updated, setUpdated] = useState(Date.now()); - const [allCodes, setAllCodes] = useState(store.getAllCode()); + const [updated, setUpdated] = useState(() => Date.now()); + const [allCodes, setAllCodes] = useState(() => store.getAllCode()); const _onShowDeploy = useCallback( (codeHash: string, constructorIndex: number): void => { diff --git a/packages/page-contracts/src/useAbi.ts b/packages/page-contracts/src/useAbi.ts index a4117412fd..4bf49bdd85 100644 --- a/packages/page-contracts/src/useAbi.ts +++ b/packages/page-contracts/src/useAbi.ts @@ -47,7 +47,7 @@ const EMPTY: AbiState = { }; export default function useAbi (initialValue: [string | null | undefined, Abi | null | undefined] = [null, null], codeHash: string | null = null, isRequired = false): UseAbi { - const [state, setAbi] = useState(fromInitial(initialValue, isRequired)); + const [state, setAbi] = useState(() => fromInitial(initialValue, isRequired)); useEffect( () => setAbi((state) => diff --git a/packages/page-explorer/src/NodeInfo/index.tsx b/packages/page-explorer/src/NodeInfo/index.tsx index e6591f1724..6f541668b6 100644 --- a/packages/page-explorer/src/NodeInfo/index.tsx +++ b/packages/page-explorer/src/NodeInfo/index.tsx @@ -34,7 +34,7 @@ function NodeInfo (): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const [info, setInfo] = useState>({}); - const [nextRefresh, setNextRefresh] = useState(Date.now()); + const [nextRefresh, setNextRefresh] = useState(() => Date.now()); useEffect((): () => void => { const _getStatus = (): void => { diff --git a/packages/page-explorer/src/Query.tsx b/packages/page-explorer/src/Query.tsx index 89f5f7eb0a..3d95bdcd7b 100644 --- a/packages/page-explorer/src/Query.tsx +++ b/packages/page-explorer/src/Query.tsx @@ -28,7 +28,7 @@ function stateFromValue (value: string): State { function Query ({ className = '', value: propsValue }: Props): React.ReactElement { const { t } = useTranslation(); - const [{ isValid, value }, setState] = useState(stateFromValue(propsValue || '')); + const [{ isValid, value }, setState] = useState(() => stateFromValue(propsValue || '')); const _setHash = useCallback( (value: string): void => setState(stateFromValue(value)), diff --git a/packages/page-parachains/src/Proposals/useProposals.ts b/packages/page-parachains/src/Proposals/useProposals.ts index 04a908c9f8..156b6e7ff3 100644 --- a/packages/page-parachains/src/Proposals/useProposals.ts +++ b/packages/page-parachains/src/Proposals/useProposals.ts @@ -37,7 +37,7 @@ export default function useProposals (): Proposals | undefined { const { api } = useApi(); const mountedRef = useIsMountedRef(); const [state, setState] = useState(); - const [trigger, setTrigger] = useState(Date.now()); + const [trigger, setTrigger] = useState(() => Date.now()); const [events, sessionIndex, approvedIds] = useCallMulti([ api.query.system.events, api.query.session.currentIndex, diff --git a/packages/page-parachains/src/modals/Propose.tsx b/packages/page-parachains/src/modals/Propose.tsx index 55f5f8865f..c2868aadb6 100644 --- a/packages/page-parachains/src/modals/Propose.tsx +++ b/packages/page-parachains/src/modals/Propose.tsx @@ -49,8 +49,8 @@ function Propose ({ className, onClose }: Props): React.ReactElement { const { api } = useApi(); const [accountId, setAccountId] = useState(null); const [name, setName] = useState(''); - const [paraId, setParaId] = useState(new BN(Date.now() % 131072)); - const [balance, setBalance] = useState(new BN(1000).mul(BN_TEN.pow(new BN(api.registry.chainDecimals)))); + const [paraId, setParaId] = useState(() => new BN(Date.now() % 131072)); + const [balance, setBalance] = useState(() => new BN(1000).mul(BN_TEN.pow(new BN(api.registry.chainDecimals[0])))); const [validators, setValidators] = useState(['']); const [{ isWasmValid, wasm }, setWasm] = useState({ isWasmValid: false, wasm: null }); const [genesisState, setGenesisState] = useState(null); diff --git a/packages/page-signing/src/Sign.tsx b/packages/page-signing/src/Sign.tsx index a3ee113f5c..f87a935e30 100644 --- a/packages/page-signing/src/Sign.tsx +++ b/packages/page-signing/src/Sign.tsx @@ -38,7 +38,7 @@ interface SignerState { function Sign ({ className = '' }: Props): React.ReactElement { const { t } = useTranslation(); - const [currentPair, setCurrentPair] = useState(keyring.getPairs()[0] || null); + const [currentPair, setCurrentPair] = useState(() => keyring.getPairs()[0] || null); const [{ data, isHexData }, setData] = useState({ data: '', isHexData: false }); const [{ isInjected }, setAccountState] = useState({ isExternal: false, isHardware: false, isInjected: false }); const [isLocked, setIsLocked] = useState(false); diff --git a/packages/page-society/src/Overview/Member.tsx b/packages/page-society/src/Overview/Member.tsx index 5449e0cace..670ed9ebea 100644 --- a/packages/page-society/src/Overview/Member.tsx +++ b/packages/page-society/src/Overview/Member.tsx @@ -26,7 +26,7 @@ function Member ({ className = '', isHead, value: { accountId, strikes } }: Prop const { t } = useTranslation(); const { api } = useApi(); const canvasRef = useRef(null); - const [canInk] = useState(api.genesisHash.eq('0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe')); + const [canInk] = useState(() => api.genesisHash.eq('0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe')); const [isInkShowing, toggleInk] = useToggle(); useEffect((): void => { diff --git a/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx b/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx index 78fa649a26..5e9fccdff8 100644 --- a/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx +++ b/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx @@ -22,8 +22,8 @@ interface Props { function SetRewardDestination ({ controllerId, defaultDestination, onClose, stashId }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const [destination, setDestination] = useState(((defaultDestination?.isAccount ? 'Account' : defaultDestination?.toString()) || 'Staked') as 'Staked'); - const [destAccount, setDestAccount] = useState(defaultDestination?.isAccount ? defaultDestination.asAccount.toString() : null); + const [destination, setDestination] = useState(() => ((defaultDestination?.isAccount ? 'Account' : defaultDestination?.toString()) || 'Staked') as 'Staked'); + const [destAccount, setDestAccount] = useState(() => defaultDestination?.isAccount ? defaultDestination.asAccount.toString() : null); const options = useMemo( () => createDestCurr(t), diff --git a/packages/page-staking/src/Actions/Account/Unbond.tsx b/packages/page-staking/src/Actions/Account/Unbond.tsx index 899a0cabb0..df915c2e7f 100644 --- a/packages/page-staking/src/Actions/Account/Unbond.tsx +++ b/packages/page-staking/src/Actions/Account/Unbond.tsx @@ -26,7 +26,7 @@ function Unbond ({ className = '', controllerId, onClose, stakingLedger, stashId const { t } = useTranslation(); const { api } = useApi(); const bondedBlocks = useUnbondDuration(); - const [maxBalance] = useState(stakingLedger?.active.unwrap() || null); + const [maxBalance] = useState(() => stakingLedger?.active.unwrap() || null); const [maxUnbond, setMaxUnbond] = useState(null); const [withMax, setWithMax] = useState(false); diff --git a/packages/page-staking/src/Payouts/index.tsx b/packages/page-staking/src/Payouts/index.tsx index 5af02381a9..88c1735575 100644 --- a/packages/page-staking/src/Payouts/index.tsx +++ b/packages/page-staking/src/Payouts/index.tsx @@ -153,8 +153,8 @@ function getOptions (api: ApiPromise, eraLength: BN | undefined, historyDepth: B function Payouts ({ className = '', isInElection, ownValidators }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const [hasOwnValidators] = useState(ownValidators.length !== 0); - const [myStashesIndex, setMyStashesIndex] = useState((api.tx.staking.payoutStakers && hasOwnValidators) ? 0 : 1); + const [hasOwnValidators] = useState(() => ownValidators.length !== 0); + const [myStashesIndex, setMyStashesIndex] = useState(() => (api.tx.staking.payoutStakers && hasOwnValidators) ? 0 : 1); const [eraSelectionIndex, setEraSelectionIndex] = useState(0); const eraLength = useCall(api.derive.session.eraLength); const historyDepth = useCall(api.query.staking.historyDepth); diff --git a/packages/react-components/src/Badge.tsx b/packages/react-components/src/Badge.tsx index 4cdde2dbdc..73c2834757 100644 --- a/packages/react-components/src/Badge.tsx +++ b/packages/react-components/src/Badge.tsx @@ -24,7 +24,7 @@ const HIGHLIGHTS = ['counter', 'highlight']; let badgeId = 0; function Badge ({ className = '', color = 'normal', hover, icon, info, isSmall, onClick }: Props): React.ReactElement | null { - const [trigger] = useState(`badge-hover-${Date.now()}-${badgeId++}`); + const [trigger] = useState(() => `badge-hover-${Date.now()}-${badgeId++}`); const extraProps = hover ? { 'data-for': trigger, 'data-tip': true } : {}; diff --git a/packages/react-components/src/DemocracyLocks.tsx b/packages/react-components/src/DemocracyLocks.tsx index e75ed8168c..099e629f81 100644 --- a/packages/react-components/src/DemocracyLocks.tsx +++ b/packages/react-components/src/DemocracyLocks.tsx @@ -86,7 +86,7 @@ function DemocracyLocks ({ className = '', value }: Props): React.ReactElement

(api.derive.chain.bestNumber); - const [trigger] = useState(`${Date.now()}-democracy-locks-${++id}`); + const [trigger] = useState(() => `${Date.now()}-democracy-locks-${++id}`); const [{ maxBalance, sorted }, setState] = useState({ maxBalance: BN_ZERO, sorted: [] }); useEffect((): void => { diff --git a/packages/react-components/src/Editor.tsx b/packages/react-components/src/Editor.tsx index 67032bb9c1..a58046767d 100644 --- a/packages/react-components/src/Editor.tsx +++ b/packages/react-components/src/Editor.tsx @@ -38,7 +38,7 @@ interface Props { * ``` */ function Editor ({ className = '', code, isValid, onEdit }: Props): React.ReactElement { - const [editorId] = useState(`flask-${Date.now()}`); + const [editorId] = useState(() => `flask-${Date.now()}`); const editorRef = useRef(null); useEffect((): void => { diff --git a/packages/react-components/src/Input.tsx b/packages/react-components/src/Input.tsx index aab2896897..eb7ff0e1fd 100644 --- a/packages/react-components/src/Input.tsx +++ b/packages/react-components/src/Input.tsx @@ -93,7 +93,7 @@ const isSelectAll = (key: string, isPreKeyDown: boolean): boolean => let counter = 0; function Input ({ autoFocus = false, children, className, defaultValue, help, icon, inputClassName, isAction = false, isDisabled = false, isDisabledError = false, isEditable = false, isError = false, isFull = false, isHidden = false, isInPlaceEditor = false, isReadOnly = false, isWarning = false, label, labelExtra, max, maxLength, min, name, onBlur, onChange, onEnter, onEscape, onKeyDown, onKeyUp, onPaste, placeholder, tabIndex, type = 'text', value, withEllipsis, withLabel }: Props): React.ReactElement { - const [stateName] = useState(`in_${counter++}_at_${Date.now()}`); + const [stateName] = useState(() => `in_${counter++}_at_${Date.now()}`); const _onBlur = useCallback( () => onBlur && onBlur(), diff --git a/packages/react-components/src/InputConsts/index.tsx b/packages/react-components/src/InputConsts/index.tsx index b1ead8e1c7..7d2fdff7d0 100644 --- a/packages/react-components/src/InputConsts/index.tsx +++ b/packages/react-components/src/InputConsts/index.tsx @@ -41,9 +41,9 @@ function getValue (api: ApiPromise, { method, section }: ConstValueBase): ConstV function InputConsts ({ className = '', defaultValue, help, label, onChange, withLabel }: Props): React.ReactElement { const { api } = useApi(); - const [optionsMethod, setOptionsMethod] = useState(keyOptions(api, defaultValue.section)); - const [optionsSection] = useState(sectionOptions(api)); - const [value, setValue] = useState(getValue(api, defaultValue)); + const [optionsMethod, setOptionsMethod] = useState(() => keyOptions(api, defaultValue.section)); + const [optionsSection] = useState(() => sectionOptions(api)); + const [value, setValue] = useState(() => getValue(api, defaultValue)); const _onKeyChange = useCallback( (newValue: ConstValueBase): void => { diff --git a/packages/react-components/src/InputExtrinsic/index.tsx b/packages/react-components/src/InputExtrinsic/index.tsx index 598c39f95e..0445999deb 100644 --- a/packages/react-components/src/InputExtrinsic/index.tsx +++ b/packages/react-components/src/InputExtrinsic/index.tsx @@ -28,8 +28,8 @@ interface Props { function InputExtrinsic ({ className = '', defaultValue, help, label, onChange, withLabel }: Props): React.ReactElement { const { api } = useApi(); - const [optionsMethod, setOptionsMethod] = useState(methodOptions(api, defaultValue.section)); - const [optionsSection] = useState(sectionOptions(api)); + const [optionsMethod, setOptionsMethod] = useState(() => methodOptions(api, defaultValue.section)); + const [optionsSection] = useState(() => sectionOptions(api)); const [value, setValue] = useState>((): SubmittableExtrinsicFunction<'promise'> => defaultValue); const _onKeyChange = useCallback( diff --git a/packages/react-components/src/InputRpc/index.tsx b/packages/react-components/src/InputRpc/index.tsx index ea648fbf6b..47d9bd24e4 100644 --- a/packages/react-components/src/InputRpc/index.tsx +++ b/packages/react-components/src/InputRpc/index.tsx @@ -30,8 +30,8 @@ interface Props { function InputRpc ({ className = '', defaultValue, help, label, onChange, withLabel }: Props): React.ReactElement { const { api } = useApi(); const rpcs = useRpcs(); - const [optionsMethod, setOptionsMethod] = useState(methodOptions(api, rpcs, defaultValue.section)); - const [optionsSection] = useState(sectionOptions(api)); + const [optionsMethod, setOptionsMethod] = useState(() => methodOptions(api, rpcs, defaultValue.section)); + const [optionsSection] = useState(() => sectionOptions(api)); const [value, setValue] = useState((): DefinitionRpcExt => defaultValue); useEffect((): void => { diff --git a/packages/react-components/src/InputStorage/index.tsx b/packages/react-components/src/InputStorage/index.tsx index b3c83dcbb8..7d80ecdb53 100644 --- a/packages/react-components/src/InputStorage/index.tsx +++ b/packages/react-components/src/InputStorage/index.tsx @@ -28,9 +28,9 @@ interface Props { function InputStorage ({ className = '', defaultValue, help, label, onChange, withLabel }: Props): React.ReactElement { const { api } = useApi(); - const [optionsMethod, setOptionsMethod] = useState(keyOptions(api, defaultValue.creator.section)); - const [optionsSection] = useState(sectionOptions(api)); - const [value, setValue] = useState>(() => defaultValue); + const [optionsMethod, setOptionsMethod] = useState(() => keyOptions(api, defaultValue.creator.section)); + const [optionsSection] = useState(() => sectionOptions(api)); + const [value, setValue] = useState>(defaultValue); const _onKeyChange = useCallback( (newValue: QueryableStorageEntry<'promise'>): void => { diff --git a/packages/react-components/src/LabelHelp.tsx b/packages/react-components/src/LabelHelp.tsx index 41b8f364e6..2ea8af8a36 100644 --- a/packages/react-components/src/LabelHelp.tsx +++ b/packages/react-components/src/LabelHelp.tsx @@ -18,7 +18,7 @@ interface Props { let id = 0; function LabelHelp ({ className = '', help, icon = 'question-circle' }: Props): React.ReactElement { - const [trigger] = useState(`label-help-${++id}`); + const [trigger] = useState(() => `label-help-${++id}`); return (

diff --git a/packages/react-components/src/Tag.tsx b/packages/react-components/src/Tag.tsx index 0716bf2e00..11a67433f3 100644 --- a/packages/react-components/src/Tag.tsx +++ b/packages/react-components/src/Tag.tsx @@ -20,7 +20,7 @@ interface Props { let tagId = 0; function Tag ({ className = '', color = 'grey', hover, isTag = true, label, size = 'small' }: Props): React.ReactElement { - const [trigger] = useState(`tag-hover-${Date.now()}-${tagId++}`); + const [trigger] = useState(() => `tag-hover-${Date.now()}-${tagId++}`); const tooltipProps = hover ? { 'data-for': trigger, 'data-tip': true } : {}; diff --git a/packages/react-hooks/src/useIpfs.ts b/packages/react-hooks/src/useIpfs.ts index d8815aad6a..82dd3ada55 100644 --- a/packages/react-hooks/src/useIpfs.ts +++ b/packages/react-hooks/src/useIpfs.ts @@ -112,7 +112,7 @@ export function extractIpfsDetails (): State { } export function useIpfs (): State { - const [state] = useState(extractIpfsDetails()); + const [state] = useState(() => extractIpfsDetails()); return state; } diff --git a/packages/react-hooks/src/useSavedFlags.ts b/packages/react-hooks/src/useSavedFlags.ts index f7729e7752..61b242371c 100644 --- a/packages/react-hooks/src/useSavedFlags.ts +++ b/packages/react-hooks/src/useSavedFlags.ts @@ -37,8 +37,8 @@ function getSetters (flags: T, setFlags: React.Dispatch (storageKey: string, initial: T): State { - const [flags, setFlags] = useState(getInitial(storageKey, initial)); - const [setters] = useState(getSetters(initial, setFlags)); + const [flags, setFlags] = useState(() => getInitial(storageKey, initial)); + const [setters] = useState(() => getSetters(initial, setFlags)); useEffect( (): void => { diff --git a/packages/react-params/src/Param/Account.tsx b/packages/react-params/src/Param/Account.tsx index 5ef85009a9..ce17342166 100644 --- a/packages/react-params/src/Param/Account.tsx +++ b/packages/react-params/src/Param/Account.tsx @@ -11,7 +11,7 @@ import { keyring } from '@polkadot/ui-keyring'; import Bare from './Bare'; function Account ({ className = '', defaultValue: { value }, isDisabled, isError, isInOption, label, onChange, withLabel }: Props): React.ReactElement { - const [defaultValue] = useState((value as string)?.toString()); + const [defaultValue] = useState(() => (value as string)?.toString()); const _onChange = useCallback( (value?: string | null): void => { diff --git a/packages/react-params/src/Param/Balance.tsx b/packages/react-params/src/Param/Balance.tsx index c58b317074..b21674e0be 100644 --- a/packages/react-params/src/Param/Balance.tsx +++ b/packages/react-params/src/Param/Balance.tsx @@ -12,7 +12,7 @@ import Bare from './Bare'; function Balance ({ className = '', defaultValue: { value }, isDisabled, isError, label, onChange, onEnter, onEscape, withLabel }: Props): React.ReactElement { const [isValid, setIsValid] = useState(false); - const [defaultValue] = useState(new BN((value as BN || '0').toString()).toString(10)); + const [defaultValue] = useState(() => new BN((value as BN || '0').toString()).toString(10)); const _onChange = useCallback( (value?: BN): void => { diff --git a/packages/react-signer/src/SignFields.tsx b/packages/react-signer/src/SignFields.tsx index 7f5f9c13ef..fc9eef96bc 100644 --- a/packages/react-signer/src/SignFields.tsx +++ b/packages/react-signer/src/SignFields.tsx @@ -21,7 +21,7 @@ interface Props { function SignFields ({ address, onChange, signedTx }: Props): React.ReactElement { const { api } = useApi(); - const [blocks, setBlocks] = useState(new BN(64)); + const [blocks, setBlocks] = useState(() => new BN(64)); const [nonce, setNonce] = useState(BN_ZERO); const { t } = useTranslation(); diff --git a/packages/react-signer/src/TxSigned.tsx b/packages/react-signer/src/TxSigned.tsx index b49e9cf0eb..34df2cc2c9 100644 --- a/packages/react-signer/src/TxSigned.tsx +++ b/packages/react-signer/src/TxSigned.tsx @@ -162,7 +162,7 @@ function TxSigned ({ className, currentItem, requestAddress }: Props): React.Rea const { api } = useApi(); const { getLedger } = useLedger(); const { queueSetTxStatus } = useContext(StatusContext); - const [flags, setFlags] = useState(extractExternal(requestAddress)); + const [flags, setFlags] = useState(() => extractExternal(requestAddress)); const [error, setError] = useState(null); const [{ isQrHashed, qrAddress, qrPayload, qrResolve }, setQrState] = useState({ isQrHashed: false, qrAddress: '', qrPayload: new Uint8Array() }); const [isBusy, setBusy] = useState(false);