declare class Foo {
  constructor(foo: string)
  foo: string
}

function Comp(props: { foo: string }) {
  let foo: Foo

  type Props = typeof props
  const update = track((props: Props) => {
    // Recreate foo whenever `props.foo` changes. Other props are ignored.
    foo = new Foo(props.foo)
  })

  return (props: Props) => {
    update(props) // Selectively rerun callbacks on rerender. Minimal boilerplate.

    return <div>{foo.foo}</div>
  }
}

function Comp2(props: { foo: string }) {
  let foo = new Foo(props.foo)

  type Props = typeof props
  const update = track((props: Props) => {
    // Update foo whenever `props.foo` changes. Other props are ignored.
    foo.update(props.foo)
  })

  return (props: Props) => {
    update(props) // Selectively rerun callbacks on rerender. Minimal boilerplate.

    return <div>{foo.foo}</div>
  }
}
