Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

How can multiple pages be model with xstate

I am trying to build a real world application with xstate but I am having trouble with modeling the application startup.

a user can enter the application start by typing the www.ex.com to go the home page but a user can also enter the application www.ex.com/any-page

can someone give an example of modeling application with multiple pages

a user can be unauthenticated an be on the login page or home page but not secure page

or

a user can be authenticated and be on any page

I want each page to have there own state that is what is prompting the question.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I want each page to have there own state that is what is prompting the question.

Don't think of it that way; at least not at first. Use a data-first approach, such as in this example: https://codesandbox.io/s/xstate-react-back-example-4q2vh

The reason is that each page isn't necessarily a "finite state" - it's just data, and all part of the same state (e.g., "viewing a page"). The best way to think about finite state is as an application's behavior at any given time. Does the behavior change when changing pages? Probably not, so use context instead of finite state.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...