0.0.3 • Published 8 years ago

react-walk v0.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

react-walk

react-walk exposes a couple functions to help you read and manipulate ReactElements as trees.

All this shit is under construction get out of here.

Example

import React from 'react';
import * as ReactWalk from './src/react-walk';
import ReactDOMServer from 'react-dom/server';

const page = (
  <html>
    <head>
      <title>I am an html5 page, psych it's me, JSX</title>
    </head>
    <body>
      <div id="poop"/>
    </body>
  </html>
);

// NOTE(brian): shit's still kinda low-level but I want to add a bunch more
// functions as we figure out what we're actually creating a library for I dunno
const hydratedPage = ReactWalk.postWalk(page, (elem) => {
  if (elem.props.id === 'poop') {
    return (
      <div>I pooped!</div>
    );
  } else {
    return elem;
  }
});

console.log(ReactDOMServer.renderToStaticMarkup(hydratedPage));
// <html><head><title>I am an html5 page, psych it&#x27;s me, JSX</title></head><body><div>I pooped!</div></body></html>