Skip to content

Latest commit

 

History

History
45 lines (34 loc) · 1021 Bytes

index.en-US.md

File metadata and controls

45 lines (34 loc) · 1021 Bytes

useChangedProps

A hook that will execute the callback with previous and present props as arguments after they changed.

Examples

Default Usage

/**
 * Desc: Do some immutable operation after props changed
 */

import React from 'react';
import { useChangedProps } from '@vergiss/chooks';

interface IProps {
  title: string
}

export default (props: IProps) => {
  useChangedProps((prevProps: IProps, props: IProps) => {
    console.log('Old Props:', prevProps, 'New Props:', props);
  });

  return (
    <div>
      <span>Props.title is: {props.title}</span>
    </div>
  )
}

API

useChangedProps(
  callback: (prevProps: IProps, props: IProps) => any
);

Params

Property Description Type Default
callback Necessary,define a callback the use the prev and present props function -