useEvent

Provides a simpler way to attach event handlers to a data object.

Example

In this example we add an event handler that is called whenever data is loaded in the data object, and set the index to the record with an ID matching what is stored in a persisted setting.

import { useCurrentRow, useEvent, usePersistedSetting } from "@olenbetong/appframe-react";

function MyComponent() {
	let [currentId, setCurrentId] = usePersistedSetting("selectedId", 1);
	let currentRow = useCurrentRow(dsMyDataObject);
	useEvent(dsMyDataObject, "onDataLoaded", () => {
		dsMyDataObject.setCurrentIndex((row) => row.ID === currentId);
	});

	return (
		<div>
			Name of the row with ID {currentId} is {currentRow.Name}
		</div>
	)
}

API

Last updated

Was this helpful?