useStillness
useStillness
connects the React component to the stillness-component control center, which provides the connected component with data from the control center and the functions it can use to manipulate the still, and you can declare the properties and methods you want
usage
import { useStillness } from 'react-stillness-component';
function Count(props) {
const [count, setCount] = useState(0);
const collected = useStillness({
mounted: (contract) => {
return 'mounted';
},
unmounted: (contract) => {
return 'unmounted';
},
collect: (contract) => {
return {
isStillness: contract.isStillness(),
stillnessId: contract.getStillnessId(),
item: contract.getStillnessItem(),
};
},
});
useEffect(() => {
console.log(collected);
}, [collected]);
return <div>...</div>;
}
Parameters
mounted
: optional, function, used to describe the initialization behavior of a stationary component with the following parametersprops
: optional, object, the props of the componentcontract
: Required, object, the contract of the component, see Contract State for more information
unmounted
: optional, function, used to describe the unmounting behavior of a stillness-component with the following argumentsprops
: optional, object, the props of the componentcontract
: Required, object, the contract of the component, see Contract State for more information
collect
: optional, function, used to describe the data collection behavior of a stillness-component with the following parametersprops
: optional, object, the props of the componentcontract
: optional, object, the contract of the component, see Contract State for more information