Git Product home page Git Product logo

Comments (4)

MicheleBertoli avatar MicheleBertoli commented on May 16, 2024

Hey @tastywheat, thanks for opening this issue.

As described in the README:

The withStatechart higher-order component takes an xstate configuration object or an xstate machine [...]

So it's already possible to create a Machine with options and use it with this library.

const SuperComponent = withStatechart(lightmachine)(Component)

I hope this helps.

from react-automata.

brianlawasdf123 avatar brianlawasdf123 commented on May 16, 2024

That sort of helps, but I'm running into an error with the guards not being recognized (I'm not sure if its xstate or react-automata).

Uncaught Error: String condition 'hasResults' is not defined on machine '(machine)'

const machine = Machine({
    "initial": "waiting",
    "states": {
        "waiting": {
            "on": {
                "SEARCH": "searching"
            },
        },
        "searching": {
            "onEntry": "search",
            "on": {
                "SUCCESS": [
                    {
                        "target": "waiting",
                        "cond": "hasResults"
                    }
                ],
            }
        }
    },
}, {
    guards: {
        hasResults: (es, eventObj) => {
            return eventObj.query.items.length > 0;
        },
    },
});

this.props.transition({ 
    type: 'SEARCH',
    query: {
        items: []
    }
})

from react-automata.

MicheleBertoli avatar MicheleBertoli commented on May 16, 2024

Hey @brianlawasdf123, I quickly tried your machine:

class App extends React.Component {
  handleSearch = () => {
    this.props.transition({
      type: 'SEARCH',
    })
  }

  handleSuccess0 = () => {
    this.props.transition({
      type: 'SUCCESS',
      query: {
        items: [],
      },
    })
  }

  handleSuccess1 = () => {
    this.props.transition({
      type: 'SUCCESS',
      query: {
        items: [{}],
      },
    })
  }

  render() {
    return (
      <React.Fragment>
        <button onClick={this.handleSearch}>SEARCH</button>
        <button onClick={this.handleSuccess0}>SUCCESS 0</button>
        <button onClick={this.handleSuccess1}>SUCCESS 1</button>
        {this.props.machineState.toString()}
      </React.Fragment>
    )
  }
}

const StateMachine = withStatechart(machine)(App)

And it seems to work:

issue

Do you mind providing more information?
Thank you very much!

from react-automata.

brianlawasdf123 avatar brianlawasdf123 commented on May 16, 2024

Ok, I just reinstalled xstate/react-automata and it works now. Sorry for the inconvenience, but thanks for looking into it.

from react-automata.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.