In Litho, components are defined using spec classes where inputs are annotated with @Prop. If a @Prop is not marked as optional = true, it is considered a required prop.
When a component is constructed using the generated builder pattern, all required props must be set. If they are omitted, the annotation processor throws a runtime exception. The litho-required-props checker performs inter-procedural analysis to detect these missing calls statically, even if the create() and build() calls are separated by complex control flows or function calls.
// Spec definition
class MyComponentSpec {
static void onCreate(
ComponentContext c,
@Prop(optional = true) String prop1,
@Prop int prop2) {
...
}
}
// Correct usage (both props provided)
MyComponent.create(c)
.prop1("My prop 1")
.prop2(256)
.build();
// Incorrect usage (prop2 is missing and will trigger MISSING_REQUIRED_PROP)
MyComponent.create(c)
.prop1("My prop 1")
.build();