Skip to content

resume

Method to resume rendering updates for the Signify instance.

Description

The resume method re-enables rendering updates after they were stopped with stop(). When resumed, components will immediately re-render if the state has changed since rendering was stopped.

Input/Output

InputTypeDescription
None-No parameters required
OutputTypeDescription
ReturnsvoidNo return value

Example

typescript
import { signify } from 'react-signify';
import React from 'react';

const sData = signify({ loading: false, items: [] });

function DataComponent() {
  const state = sData.use();
  
  const loadData = async () => {
    // Stop rendering during loading process
    sData.stop();
    
    sData.set(({ value }) => {
      value.loading = true;
    });
    
    try {
      const response = await fetch('/api/data');
      const items = await response.json();
      
      sData.set(({ value }) => {
        value.items = items;
        value.loading = false;
      });
    } catch (error) {
      sData.set(({ value }) => {
        value.loading = false;
      });
    } finally {
      // Resume rendering - component updates once with final state
      sData.resume();
    }
  };
  
  return (
    <div>
      {state.loading ? (
        <p>Loading...</p>
      ) : (
        <ul>
          {state.items.map((item, index) => (
            <li key={index}>{item}</li>
          ))}
        </ul>
      )}
      <button onClick={loadData}>Load Data</button>
    </div>
  );
}

Released under the MIT License.