Skip to content
Compare
Choose a tag to compare
@github-actions github-actions released this 08 Apr 21:27
· 8 commits to main since this release
8b4e6e8

Patch Changes

  • #6504 e533dbbdade9d5ffdbd5aa7c446d958dd1980d43 Thanks @calebpollman! - feat(storage-browser): add defaultValue, value, and onValueChange props

    Controlled StorageBrowser

    'use client';
    
    import React from 'react';
    import { useRouter, usePathname, useSearchParams } from 'next/navigation';
    
    import { StorageBrowser } from '@aws-amplify/ui-react-storage';
    import { StorageBrowserEventValue } from '@aws-amplify/ui-react-storage/browser';
    
    export default function Page() {
      const router = useRouter();
      const pathname = usePathname();
      const params = useSearchParams();
    
      const value = params.get('value');
    
      const handleValueChange = React.useCallback(
        (nextValue: StorageBrowserEventValue) => {
          const nextParams = new URLSearchParams();
          nextParams.set('value', JSON.stringify(nextValue));
    
          router.push(`${pathname}?${nextParams.toString()}`);
        },
        [pathname, router]
      );
    
      return (
        <StorageBrowser
          onValueChange={handleValueChange}
          value={value ? JSON.parse(value) : null}
        />
      );
    }

    Initialize with defaultValue

    'use client';
    
    import { StorageBrowser } from '@aws-amplify/ui-react-storage';
    import { useSearchParams } from 'next/navigation';
    
    export default function Page() {
      const params = useSearchParams();
    
      const value = params.get('value');
    
      return <StorageBrowser defaultValue={value ? JSON.parse(value) : null} />;
    }
  • Updated dependencies [e4d8cc8c04dd428d38289085a9bf797b87c058a2, e533dbbdade9d5ffdbd5aa7c446d958dd1980d43]: