Skip to content
Snippets Groups Projects
Unverified Commit 28b5124d authored by Matiss Janis Aboltins's avatar Matiss Janis Aboltins Committed by GitHub
Browse files

:rotating_light: re-enable react-hooks/rules-of-hooks eslint rule (#715)

parent 08b997a7
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,6 @@ module.exports = { ...@@ -17,7 +17,6 @@ module.exports = {
// TODO: re-enable these rules // TODO: re-enable these rules
'import/no-anonymous-default-export': 'off', 'import/no-anonymous-default-export': 'off',
'react/destructuring-assignment': 'off', 'react/destructuring-assignment': 'off',
'react-hooks/rules-of-hooks': 'off',
'react-hooks/exhaustive-deps': 'off', 'react-hooks/exhaustive-deps': 'off',
'import/no-useless-path-segments': 'error', 'import/no-useless-path-segments': 'error',
......
...@@ -69,6 +69,7 @@ function AccountSyncCheck({ ...@@ -69,6 +69,7 @@ function AccountSyncCheck({
getAccounts, getAccounts,
addNotification, addNotification,
}) { }) {
let [open, setOpen] = useState(false);
if (!failedAccounts) { if (!failedAccounts) {
return null; return null;
} }
...@@ -78,8 +79,6 @@ function AccountSyncCheck({ ...@@ -78,8 +79,6 @@ function AccountSyncCheck({
return null; return null;
} }
let [open, setOpen] = useState(false);
let account = accounts.find(account => account.id === id); let account = accounts.find(account => account.id === id);
let { type, code } = error; let { type, code } = error;
let showAuth = let showAuth =
......
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useMemo } from 'react';
import * as d from 'date-fns'; import * as d from 'date-fns';
...@@ -19,7 +19,6 @@ import { cashFlowByDate } from './graphs/cash-flow-spreadsheet'; ...@@ -19,7 +19,6 @@ import { cashFlowByDate } from './graphs/cash-flow-spreadsheet';
import CashFlowGraph from './graphs/CashFlowGraph'; import CashFlowGraph from './graphs/CashFlowGraph';
import Header from './Header'; import Header from './Header';
import useReport from './useReport'; import useReport from './useReport';
import { useArgsMemo } from './util';
function CashFlow() { function CashFlow() {
const [allMonths, setAllMonths] = useState(null); const [allMonths, setAllMonths] = useState(null);
...@@ -36,10 +35,11 @@ function CashFlow() { ...@@ -36,10 +35,11 @@ function CashFlow() {
return numDays > 31 * 3; return numDays > 31 * 3;
}); });
const data = useReport( const params = useMemo(
'cash_flow', () => cashFlowByDate(start, end, isConcise),
useArgsMemo(cashFlowByDate)(start, end, isConcise), [start, end, isConcise],
); );
const data = useReport('cash_flow', params);
useEffect(() => { useEffect(() => {
async function run() { async function run() {
......
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useMemo } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import * as d from 'date-fns'; import * as d from 'date-fns';
...@@ -16,7 +16,7 @@ import netWorthSpreadsheet from './graphs/net-worth-spreadsheet'; ...@@ -16,7 +16,7 @@ import netWorthSpreadsheet from './graphs/net-worth-spreadsheet';
import NetWorthGraph from './graphs/NetWorthGraph'; import NetWorthGraph from './graphs/NetWorthGraph';
import Header from './Header'; import Header from './Header';
import useReport from './useReport'; import useReport from './useReport';
import { fromDateRepr, useArgsMemo } from './util'; import { fromDateRepr } from './util';
function NetWorth({ accounts }) { function NetWorth({ accounts }) {
const [allMonths, setAllMonths] = useState(null); const [allMonths, setAllMonths] = useState(null);
...@@ -25,10 +25,11 @@ function NetWorth({ accounts }) { ...@@ -25,10 +25,11 @@ function NetWorth({ accounts }) {
); );
const [end, setEnd] = useState(monthUtils.currentMonth()); const [end, setEnd] = useState(monthUtils.currentMonth());
const data = useReport( const params = useMemo(
'net_worth', () => netWorthSpreadsheet(start, end, accounts),
useArgsMemo(netWorthSpreadsheet)(start, end, accounts), [start, end, accounts],
); );
const data = useReport('net_worth', params);
useEffect(() => { useEffect(() => {
async function run() { async function run() {
......
import React from 'react'; import React, { useMemo } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
...@@ -19,7 +19,6 @@ import netWorthSpreadsheet from './graphs/net-worth-spreadsheet'; ...@@ -19,7 +19,6 @@ import netWorthSpreadsheet from './graphs/net-worth-spreadsheet';
import NetWorthGraph from './graphs/NetWorthGraph'; import NetWorthGraph from './graphs/NetWorthGraph';
import Tooltip from './Tooltip'; import Tooltip from './Tooltip';
import useReport from './useReport'; import useReport from './useReport';
import { useArgsMemo } from './util';
function Card({ flex, to, style, children }) { function Card({ flex, to, style, children }) {
const containerProps = { flex, margin: 15 }; const containerProps = { flex, margin: 15 };
...@@ -63,10 +62,11 @@ function NetWorthCard({ accounts }) { ...@@ -63,10 +62,11 @@ function NetWorthCard({ accounts }) {
const end = monthUtils.currentMonth(); const end = monthUtils.currentMonth();
const start = monthUtils.subMonths(end, 5); const start = monthUtils.subMonths(end, 5);
const data = useReport( const params = useMemo(
'net_worth', () => netWorthSpreadsheet(start, end, accounts),
useArgsMemo(netWorthSpreadsheet)(start, end, accounts), [start, end, accounts],
); );
const data = useReport('net_worth', params);
if (!data) { if (!data) {
return null; return null;
...@@ -114,10 +114,8 @@ function CashFlowCard() { ...@@ -114,10 +114,8 @@ function CashFlowCard() {
const end = monthUtils.currentDay(); const end = monthUtils.currentDay();
const start = monthUtils.currentMonth() + '-01'; const start = monthUtils.currentMonth() + '-01';
const data = useReport( const params = useMemo(() => simpleCashFlow(start, end), [start, end]);
'cash_flow_simple', const data = useReport('cash_flow_simple', params);
useArgsMemo(simpleCashFlow)(start, end),
);
if (!data) { if (!data) {
return null; return null;
} }
......
import { useMemo } from 'react';
import { runQuery } from 'loot-core/src/client/query-helpers'; import { runQuery } from 'loot-core/src/client/query-helpers';
export function useArgsMemo(func) {
return (...args) => {
return useMemo(() => func(...args), args);
};
}
export function fromDateRepr(date) { export function fromDateRepr(date) {
return date.slice(0, 7); return date.slice(0, 7);
} }
......
...@@ -130,15 +130,16 @@ function reducer(state, action) { ...@@ -130,15 +130,16 @@ function reducer(state, action) {
} }
function SchedulePreview({ previewDates }) { function SchedulePreview({ previewDates }) {
const dateFormat = useSelector(state =>
(state.prefs.local.dateFormat || 'MM/dd/yyyy')
.replace('MM', 'M')
.replace('dd', 'd'),
);
if (!previewDates) { if (!previewDates) {
return null; return null;
} }
let dateFormat = useSelector(
state => state.prefs.local.dateFormat || 'MM/dd/yyyy',
);
dateFormat = dateFormat.replace('MM', 'M').replace('dd', 'd');
let content = null; let content = null;
if (typeof previewDates === 'string') { if (typeof previewDates === 'string') {
content = <Text>{previewDates}</Text>; content = <Text>{previewDates}</Text>;
......
...@@ -109,11 +109,12 @@ export function useDroppable({ types, id, onDrop, onLongHover }) { ...@@ -109,11 +109,12 @@ export function useDroppable({ types, id, onDrop, onLongHover }) {
export const DropHighlightPosContext = React.createContext(null); export const DropHighlightPosContext = React.createContext(null);
export function DropHighlight({ pos, offset = {} }) { export function DropHighlight({ pos, offset = {} }) {
let itemPos = useContext(DropHighlightPosContext);
if (pos == null) { if (pos == null) {
return null; return null;
} }
let itemPos = useContext(DropHighlightPosContext);
let topOffset = (itemPos === 'first' ? 2 : 0) + (offset.top || 0); let topOffset = (itemPos === 'first' ? 2 : 0) + (offset.top || 0);
let bottomOffset = (itemPos === 'last' ? 2 : 0) + (offset.bottom || 0); let bottomOffset = (itemPos === 'last' ? 2 : 0) + (offset.bottom || 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment