import React from 'react';

export default function Predicate(props) {
    const { fallback, value, calc } = props;

    const [next, setNext] = React.useState(calc(value));

    React.useEffect(() => {
        setNext(calc(value));
    }, [value]);

    return next === true ? props.children : React.cloneElement(fallback, { state: next });
}
