@germtf/react-json

0.1.5 • Public • Published

ReactJSON

This repository has a reconciler to convert React trees to JSON.

const Player = () => {
  return (
    <player>
      <life>20</life>
      <mana>20</mana>
    </player>
  );
};

const State = () => {
  return (
    <state>
      <Player />
      <Player />
    </state>
  );
};

const root = {};

ReactJSON.mount(<State />, root);

console.log(root);

// {
//   "children": [
//     {
//       "type": "state",
//       "children": [
//         {
//           "type": "player",
//           "children": [
//             {
//               "type": "life",
//               "children": [
//                 {
//                   "type": "text",
//                   "value": "20"
//                 }
//               ]
//             },
//             {
//               "type": "mana",
//               "children": [
//                 {
//                   "type": "text",
//                   "value": "20"
//                 }
//               ]
//             }
//           ]
//         },
//         {
//           "type": "player",
//           "children": [
//             {
//               "type": "life",
//               "children": [
//                 {
//                   "type": "text",
//                   "value": "20"
//                 }
//               ]
//             },
//             {
//               "type": "mana",
//               "children": [
//                 {
//                   "type": "text",
//                   "value": "20"
//                 }
//               ]
//             }
//           ]
//         }
//       ]
//     }
//   ]
// }

Readme

Keywords

none

Package Sidebar

Install

npm i @germtf/react-json

Weekly Downloads

1

Version

0.1.5

License

none

Unpacked Size

316 kB

Total Files

8

Last publish

Collaborators

  • germtf