Function useQuery

  • Returns a Realm.Collection of Realm.Objects from a given type. The hook will update on any changes to any object in the collection and return an empty array if the collection is empty.

    The result of this can be consumed directly by the data argument of any React Native VirtualizedList or FlatList. If the component used for the list's renderItem prop is React.Memoized, then only the modified object will re-render.

    Type Parameters

    • T

    Parameters

    • options: QueryHookOptions<T>
    • Optional deps: DependencyList

      An array of dependencies that will be passed to React.useMemo

    Returns Results<T & Object<T, never>>

    a collection of realm objects or an empty array

    Example

    // Return all collection items
    const collection = useQuery({ type: Object });

    // Return all collection items sorted by name and filtered by category
    const filteredAndSorted = useQuery({
    type: Object,
    query: (collection) => collection.filtered('category == $0',category).sorted('name'),
    }, [category]);

    // Return all collection items sorted by name and filtered by category, triggering re-renders only if "name" changes
    const filteredAndSorted = useQuery({
    type: Object,
    query: (collection) => collection.filtered('category == $0',category).sorted('name'),
    keyPaths: ["name"]
    }, [category]);
  • Returns a Realm.Collection of Realm.Objects from a given type. The hook will update on any changes to any object in the collection and return an empty array if the collection is empty.

    The result of this can be consumed directly by the data argument of any React Native VirtualizedList or FlatList. If the component used for the list's renderItem prop is React.Memoized, then only the modified object will re-render.

    Type Parameters

    Parameters

    Returns Results<T>

    a collection of realm objects or an empty array

    Example

    // Return all collection items
    const collection = useQuery({ type: Object });

    // Return all collection items sorted by name and filtered by category
    const filteredAndSorted = useQuery({
    type: Object,
    query: (collection) => collection.filtered('category == $0',category).sorted('name'),
    }, [category]);

    // Return all collection items sorted by name and filtered by category, triggering re-renders only if "name" changes
    const filteredAndSorted = useQuery({
    type: Object,
    query: (collection) => collection.filtered('category == $0',category).sorted('name'),
    keyPaths: ["name"]
    }, [category]);
  • Returns a Realm.Collection of Realm.Objects from a given type. The hook will update on any changes to any object in the collection and return an empty array if the collection is empty.

    The result of this can be consumed directly by the data argument of any React Native VirtualizedList or FlatList. If the component used for the list's renderItem prop is React.Memoized, then only the modified object will re-render.

    Type Parameters

    • T

    Parameters

    • type: string

    Returns Results<T & Object<T, never>>

    a collection of realm objects or an empty array

    Example

    // Return all collection items
    const collection = useQuery({ type: Object });

    // Return all collection items sorted by name and filtered by category
    const filteredAndSorted = useQuery({
    type: Object,
    query: (collection) => collection.filtered('category == $0',category).sorted('name'),
    }, [category]);

    // Return all collection items sorted by name and filtered by category, triggering re-renders only if "name" changes
    const filteredAndSorted = useQuery({
    type: Object,
    query: (collection) => collection.filtered('category == $0',category).sorted('name'),
    keyPaths: ["name"]
    }, [category]);
  • Returns a Realm.Collection of Realm.Objects from a given type. The hook will update on any changes to any object in the collection and return an empty array if the collection is empty.

    The result of this can be consumed directly by the data argument of any React Native VirtualizedList or FlatList. If the component used for the list's renderItem prop is React.Memoized, then only the modified object will re-render.

    Type Parameters

    Parameters

    • type: RealmClassType<T>

    Returns Results<T>

    a collection of realm objects or an empty array

    Example

    // Return all collection items
    const collection = useQuery({ type: Object });

    // Return all collection items sorted by name and filtered by category
    const filteredAndSorted = useQuery({
    type: Object,
    query: (collection) => collection.filtered('category == $0',category).sorted('name'),
    }, [category]);

    // Return all collection items sorted by name and filtered by category, triggering re-renders only if "name" changes
    const filteredAndSorted = useQuery({
    type: Object,
    query: (collection) => collection.filtered('category == $0',category).sorted('name'),
    keyPaths: ["name"]
    }, [category]);
  • Returns a Realm.Collection of Realm.Objects from a given type. The hook will update on any changes to any object in the collection and return an empty array if the collection is empty.

    The result of this can be consumed directly by the data argument of any React Native VirtualizedList or FlatList. If the component used for the list's renderItem prop is React.Memoized, then only the modified object will re-render.

    Type Parameters

    • T

    Parameters

    • type: string
    • Optional query: QueryCallback<T>
    • Optional deps: DependencyList

      An array of dependencies that will be passed to React.useMemo

    Returns Results<T & Object<T, never>>

    a collection of realm objects or an empty array

    Example

    // Return all collection items
    const collection = useQuery({ type: Object });

    // Return all collection items sorted by name and filtered by category
    const filteredAndSorted = useQuery({
    type: Object,
    query: (collection) => collection.filtered('category == $0',category).sorted('name'),
    }, [category]);

    // Return all collection items sorted by name and filtered by category, triggering re-renders only if "name" changes
    const filteredAndSorted = useQuery({
    type: Object,
    query: (collection) => collection.filtered('category == $0',category).sorted('name'),
    keyPaths: ["name"]
    }, [category]);
  • Returns a Realm.Collection of Realm.Objects from a given type. The hook will update on any changes to any object in the collection and return an empty array if the collection is empty.

    The result of this can be consumed directly by the data argument of any React Native VirtualizedList or FlatList. If the component used for the list's renderItem prop is React.Memoized, then only the modified object will re-render.

    Type Parameters

    Parameters

    • type: RealmClassType<T>
    • Optional query: QueryCallback<T>
    • Optional deps: DependencyList

      An array of dependencies that will be passed to React.useMemo

    Returns Results<T>

    a collection of realm objects or an empty array

    Example

    // Return all collection items
    const collection = useQuery({ type: Object });

    // Return all collection items sorted by name and filtered by category
    const filteredAndSorted = useQuery({
    type: Object,
    query: (collection) => collection.filtered('category == $0',category).sorted('name'),
    }, [category]);

    // Return all collection items sorted by name and filtered by category, triggering re-renders only if "name" changes
    const filteredAndSorted = useQuery({
    type: Object,
    query: (collection) => collection.filtered('category == $0',category).sorted('name'),
    keyPaths: ["name"]
    }, [category]);

Generated using TypeDoc