How to use the react-component-tree.serialize function in react-component-tree

To help you get started, we’ve selected a few react-component-tree examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Tettra / react-visual-diff / example / src / App.js View on Github external
import ExampleComponent from 'react-deep-diff'

const last = array => array[array.length - 1]
const first = array => array[0]
const second = array => array[1]
const beforeLast = array => array[array.length - 2]

const el1 = <div>
  Hello
  <span>Wor<span>What up</span></span>
</div>


console.log('wat', serialize(el1))

const serialized = serialize(el1)

// console.log('json react', JSON.stringify(el1))
// 
// const el2 = <div>
//   Hello
//   <span>World<span>how do you do</span></span>
//   <div>
//     <h1>This is a new Element</h1>
//   </div>
// </div>
// 
// // path be like ["props", "children", 1, "props", "children", 1, "props", "children"]
// const changeReactElement = (element, path, change, renderChange) =&gt; {
//   // first path has to always be props, if not return element
//   console.log('path', path)
//   if (path[0] !== 'props') {
github Tettra / react-visual-diff / example / src / App.js View on Github external
import takeWhile from 'lodash/takeWhile'
import { serialize, render } from 'react-component-tree'
import ExampleComponent from 'react-deep-diff'

const last = array =&gt; array[array.length - 1]
const first = array =&gt; array[0]
const second = array =&gt; array[1]
const beforeLast = array =&gt; array[array.length - 2]

const el1 = <div>
  Hello
  <span>Wor<span>What up</span></span>
</div>


console.log('wat', serialize(el1))

const serialized = serialize(el1)

// console.log('json react', JSON.stringify(el1))
// 
// const el2 = <div>
//   Hello
//   <span>World<span>how do you do</span></span>
//   <div>
//     <h1>This is a new Element</h1>
//   </div>
// </div>
// 
// // path be like ["props", "children", 1, "props", "children", 1, "props", "children"]
// const changeReactElement = (element, path, change, renderChange) =&gt; {
//   // first path has to always be props, if not return element
github skidding / react-component-playground / src / components / component-playground.jsx View on Github external
onFixtureUpdate: function() {
    if (!this.refs.preview ||
        // Don't update fixture contents while the user is editing the fixture
        this.state.isEditorFocused) {
      return;
    }

    var snapshot = ComponentTree.serialize(this.refs.preview);

    // Continue to ignore unserializable props
    var serializableSnapshot =
        _.omit(snapshot, _.keys(this.state.fixtureUnserializableProps));

    this.setState({
      fixtureContents: serializableSnapshot,
      fixtureUserInput:
          this.constructor.getStringifiedFixtureContents(serializableSnapshot),
      isFixtureUserInputValid: true
    });
  },
github FRC1458 / TurtleDashboard / src / components / dashboard / Dashboard.js View on Github external
_save(){
        let data = ComponentTree.serialize(this);
        console.log(JSON.stringify(data));
        for(var i = 0; i &lt; data.state.childrenSet.length; i++) {
            data.state.childrenSet[i].x = data.state.children[""+i].x;
            data.state.childrenSet[i].y = data.state.children[""+i].y;
            data.state.childrenSet[i].height = data.state.children[""+i].height;
            data.state.childrenSet[i].width = data.state.children[""+i].width;
        }
        alert(JSON.stringify(data.state.childrenSet));
    }
github react-cosmos / react-cosmos / packages / react-cosmos / src / components / proxies / StateProxy.jsx View on Github external
getStateTree(componentRef) {
      return ReactComponentTree.serialize(componentRef).state;
    }
github topliceanu / learn / js / react / shopping-cart / entry.js View on Github external
window._exportState = () => {
    return serialize(cart);
};
window._importState = (snapshot) => {
github skidding / flatris / src / components / FlatrisStatePersistor.jsx View on Github external
onUnload() {
    var snapshot = ComponentTree.serialize(this.refs.flatrisStatePreview);
    localStorage.setItem('flatrisState', JSON.stringify(snapshot.state));
  }
}

react-component-tree

Serialize and reproduce the state of an entire tree of React components

MIT
Latest version published 7 years ago

Package Health Score

70 / 100
Full package analysis

Similar packages