Comments (4)
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.
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.
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:
Do you mind providing more information?
Thank you very much!
from react-automata.
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)
- componentWillTransition not working HOT 7
- Changelog HOT 1
- Invariant violation error when componentState changed but not machineState HOT 1
- Understanding testStateMachine HOT 3
- Is testStateMachine code included in prod builds? HOT 2
- Actions are not updated when the transition is to the same state HOT 1
- handling nested state HOT 1
- Upgrade guide for v4 HOT 1
- ReferenceError: statechart is not defined when testing HOT 3
- Typescript support? HOT 1
- Future plans for react automata HOT 5
- Question: Is history nodes supported ? HOT 3
- Hook? HOT 3
- Sponsorship
- Initial Data is not set (or at least not accessable in props)
- Update to the latest version of XState
- Error while using <State>
- Flow suppport
- Jest test - error with react-automata
- Is this repo no longer being worked upon ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-automata.