Skip to content

Commit ae4648c

Browse files
authored
Merge pull request #189 from GizzZmo/copilot/fix-code-quality-check
fix: resolve Code Quality Check lint failures (set-state-in-effect, no-undef, no-unused-vars)
2 parents 0660897 + 3495e28 commit ae4648c

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

docs/widget-api/examples/weather.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const WeatherExampleWidget: React.FC = () => {
4444
if (!res.ok) throw new Error('API request failed');
4545
const data = await res.json();
4646
setWeather(data.current_weather);
47-
} catch (e) {
47+
} catch (_e) {
4848
setError('Could not fetch weather data');
4949
} finally {
5050
setLoading(false);

eslint.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ export default [
1616
],
1717
},
1818
js.configs.recommended,
19+
{
20+
files: ['scripts/**/*.mjs', 'scripts/**/*.js'],
21+
languageOptions: {
22+
globals: {
23+
console: 'readonly',
24+
process: 'readonly',
25+
__dirname: 'readonly',
26+
__filename: 'readonly',
27+
module: 'readonly',
28+
require: 'readonly',
29+
exports: 'readonly',
30+
},
31+
},
32+
},
1933
{
2034
files: ['public/sw.js'],
2135
languageOptions: {

hooks/useContainerWidth.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, useRef, useCallback } from 'react';
1+
import { useState, useRef, useCallback, useLayoutEffect } from 'react';
22

33
/**
44
* Observe container width for ResponsiveGridLayout.
@@ -16,12 +16,21 @@ export function useContainerWidth(defaultWidth = 1200) {
1616
if (w > 0) setWidth(w);
1717
}, []);
1818

19-
useEffect(() => {
20-
setMounted(true);
21-
measure();
19+
// Callback ref: setMounted is called outside an effect body, when the element attaches.
20+
const containerRef = useCallback(
21+
(el: HTMLDivElement | null) => {
22+
ref.current = el;
23+
if (el) setMounted(true);
24+
},
25+
[],
26+
);
27+
28+
useLayoutEffect(() => {
2229
const el = ref.current;
2330
if (!el) return;
2431

32+
measure();
33+
2534
if (typeof ResizeObserver !== 'undefined') {
2635
const ro = new ResizeObserver(() => measure());
2736
ro.observe(el);
@@ -32,5 +41,5 @@ export function useContainerWidth(defaultWidth = 1200) {
3241
return () => window.removeEventListener('resize', measure);
3342
}, [measure]);
3443

35-
return { width, containerRef: ref, mounted };
44+
return { width, containerRef, mounted };
3645
}

0 commit comments

Comments
 (0)