Locospec

View

View configuration.

👁️ View

The View component is a context provider used inside the LensProvider to manage view-specific configuration, state, and layout behavior.

It acts as a boundary for each lens view and is responsible for handling state like filters, search queries, modals/sheets, and view identifiers. All components like Datatable, SimpleFilters, and custom Lens-compatible widgets rely on the View context to function properly.


📦 Import

import { View } from "@locospec/lens-react";

🧠 Why View is Needed

View provides:

  • A scoped context for a single lens configuration, especially useful when rendering multiple views in the same app.
  • Access to view-level configuration fetched by LensProvider (based on a viewId).
  • State for filters, search query, and sheet/modal visibility.
  • A reference to the container (ref) for sheet positioning and dynamic layout changes.
  • An ID (view_uuid) to uniquely track view instance, useful for analytics or debugging.

🧩 Props

PropTypeDescription
viewIdstring (default: "default")The key to access the correct config object from the global Lens config.
childrenReact.ReactNodeComponents to render inside the view.
viewConfigurationRecord<string, any>Additional view-level context, if needed (e.g., dynamic tokens, UI options).
showSheetPropbooleanControls visibility of the Lens Sheet (sidebar modal).
setShowSheetProp(val: boolean) => voidOptional external control to manage the Sheet toggle.

🧪 Example

<View viewId="orders-view">
  <SimpleFilters />
  <SearchInput />
  <Datatable />
</View>

This will:

  • Load config from the orders-view key inside the global Lens config.
  • Provide filter and search state to all child components.
  • Automatically render a sheet modal (LensSidebar) controlled by internal or external state.

🔄 Internally Provides (via ViewContext)

You can access the following via useContext(ViewContext):

KeyDescription
filtersCurrent filter object (used in API calls).
searchQueryCurrent search string.
setFiltersMethod to update filters.
searchMethod to update search query.
viewIdThe unique ID of this view.
view_uuidA random ID used internally for uniqueness.
viewChildRefA ref to the main container div.
configThe Lens config for this view.
showSheetWhether the Lens Sheet is open.
setShowSheetMethod to toggle the sheet modal.
contextAny extra user-passed context (like filters, user IDs, etc).

⚠️ Note

  • The View must be used inside a LensProvider, otherwise it will throw an error.
  • The viewId should match a key inside the config returned by the Lens API or configCallback.

On this page