Skip to content

Commit 1cf8962

Browse files
committed
Reduce code duplication by forwaring use(Layout)EffectOnce to the non-once version, instead of replicating jsEmit
1 parent 1164d11 commit 1cf8962

2 files changed

Lines changed: 2 additions & 30 deletions

File tree

src/Feliz/React/React.fs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,6 @@ useEffect(() => {
208208
[<Hook>]
209209
static member inline useEffectOnce(setup: unit -> unit) : unit = React.useEffect (setup, [||])
210210

211-
/// The `useEffect` hook that creates a disposable effect for React function components.
212-
/// This effect has no dependencies which means the effect is re-executed on every re-render.
213-
/// To make the effect run once (for example you subscribe once to web sockets) then provide an empty array
214-
/// for the dependencies: `React.useEffect(disposableEffect, [| |])`.
215-
[<Hook>]
216-
static member inline useEffectOnce(setup: Func<unit, (unit -> unit)>) : unit =
217-
JsInterop.emitJsExpr
218-
(setup)
219-
"import {useEffect} from 'react';
220-
useEffect(() => {
221-
const setup = $0();
222-
return setup;
223-
}, []);"
224-
225211
/// The `useEffect` hook that creates a disposable effect for React function components.
226212
/// This effect has no dependencies which means the effect is re-executed on every re-render.
227213
/// To make the effect run once (for example you subscribe once to web sockets) then provide an empty array
@@ -308,27 +294,13 @@ useLayoutEffect(() => {
308294
/// The signature is identical to useEffect, but it fires synchronously after all DOM mutations. Use this to read layout from the DOM and synchronously re-render. Updates scheduled inside useLayoutEffect will be flushed synchronously, before the browser has a chance to paint.
309295
static member inline useLayoutEffectOnce(setup: unit -> unit) : unit = React.useLayoutEffect (setup, [||])
310296

311-
/// The `useLayoutEffect` hook that creates a disposable effect for React function components.
312-
/// This effect has no dependencies which means the effect is re-executed on every re-render.
313-
/// To make the effect run once (for example you subscribe once to web sockets) then provide an empty array
314-
/// for the dependencies: `React.useLayoutEffect(disposableEffect, [| |])`.
315-
/// The signature is identical to useEffect, but it fires synchronously after all DOM mutations. Use this to read layout from the DOM and synchronously re-render. Updates scheduled inside useLayoutEffect will be flushed synchronously, before the browser has a chance to paint.
316-
static member inline useLayoutEffectOnce(setup: Func<unit, (unit -> unit)>) : unit =
317-
JsInterop.emitJsExpr
318-
(setup)
319-
"import {useLayoutEffect} from 'react';
320-
useLayoutEffect(() => {
321-
const setup = $0();
322-
return setup;
323-
}, []);"
324-
325297
/// The `useLayoutEffect` hook that creates a disposable effect for React function components.
326298
/// This effect has no dependencies which means the effect is re-executed on every re-render.
327299
/// To make the effect run once (for example you subscribe once to web sockets) then provide an empty array
328300
/// for the dependencies: `React.useLayoutEffect(disposableEffect, [| |])`.
329301
/// The signature is identical to useEffect, but it fires synchronously after all DOM mutations. Use this to read layout from the DOM and synchronously re-render. Updates scheduled inside useLayoutEffect will be flushed synchronously, before the browser has a chance to paint.
330302
static member inline useLayoutEffectOnce(setup: unit -> (unit -> unit)) : unit =
331-
React.useLayoutEffectOnce (Func<_, _> setup)
303+
React.useLayoutEffect (Func<_, _> setup, [||])
332304

333305
/// The `useLayoutEffect` hook that creates a disposable effect for React function components.
334306
/// This effect has no dependencies which means the effect is re-executed on every re-render.

tests/Feliz/ReactBindings/UseLayoutEffect.test.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module Components =
7373

7474
]
7575

76-
// #714
76+
/// #714
7777
[<ReactComponent>]
7878
static member OnlyCleanup(disposeEffect: unit -> unit) =
7979
React.useLayoutEffectOnce ((fun () -> fun () -> disposeEffect ()))

0 commit comments

Comments
 (0)