avoidPassingDataToParentInComponentAvoid passing data to parents in an effect. Instead, fetch "{{data}}" in the parent and pass it down to {{name}} as a prop.small-rules/no-pass-data-to-parentDisallow passing data to parents in an effect.
Ported from
eslint-plugin-react-you-might-not-need-an-effect/no-pass-data-to-parent.
The upstream rule points at the “Passing data to the
parent” section of the
React docs, so that’s where the intent comes from.
This flags an effect that calls a parent callback with an argument that’s none of the usual suspects: not state, not a prop, not a ref, not a constant. The rule literally identifies data by process of elimination. What you’ve built is two-way data flow, and the parent can’t act on it until the child renders, the effect runs, and the callback fires. Always a render late.
Fetch or compute in the parent and pass the result down, or return it from a hook. On Roblox the parent is usually a screen controller that should own the data anyway.
avoidPassingDataToParentInComponentAvoid passing data to parents in an effect. Instead, fetch "{{data}}" in the parent and pass it down to {{name}} as a prop.avoidPassingDataToParentInHookAvoid passing data to parents in an effect. Instead, return "{{data}}" from {{name}}.This rule accepts one options object after the severity.
import React, { useEffect } from "@rbxts/react";
declare function useSomeAPI(): string;
export function Child({ onFetched }: { onFetched: (data: string) => void }): React.Element { const data = useSomeAPI();
useEffect(() => { onFetched(data); }, [onFetched, data]);
return <textlabel Text={data} />;}import React from "@rbxts/react";
declare function useSomeAPI(): string;
function Child({ data }: { data: string }): React.Element { return <textlabel Text={data} />;}
export function Parent(): React.Element { const data = useSomeAPI();
return <Child data={data} />;}