API design question
See original GitHub issueHello Daishi. Trying to wrap my head around your library.
I’m curious why did you design the reducer API like this:
const initialState = { counter: 0 }; // initialState is not optional.
const { GlobalStateProvider, dispatch, useGlobalState } = createStore(reducer, initialState);
const Counter = () => {
const [value] = useGlobalState('counter');
return (
<div>
<span>Counter: {value}</span>
<button onClick={() => dispatch({ type: 'increment' })}>+1</button>
<button onClick={() => dispatch({ type: 'decrement' })}>-1</button>
</div>
);
};
and not like this:
const initialState = { counter: 0 }; // initialState is not optional.
const { GlobalStateProvider, useGlobalState } = createStore(reducer, initialState);
const Counter = () => {
const [value, dispatch] = useGlobalState('counter');
return (
<div>
<span>Counter: {value}</span>
<button onClick={() => dispatch({ type: 'increment' })}>+1</button>
<button onClick={() => dispatch({ type: 'decrement' })}>-1</button>
</div>
);
};
I’m not sure about all pros & cons, except that the second one looks more similar to basic setState
option (which is a plus). Will appreciate your clarification.
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (8 by maintainers)
Top Results From Across the Web
Top REST API Interview Questions and Answers (2023)
REST API Basic Interview Questions · 1. What do you understand by RESTful Web Services? · 2. What is a REST Resource? ·...
Read more >13 API Design Interview Questions to Ask Developers ... - Twine
Question 1: What is API Design? ... API Design is defining interfaces/contracts for interacting between systems (server-to-server or server-to- ...
Read more >Answers To The Most Common REST API Interview Questions
The most commonly asked REST API interview questions to prep for system design, software engineering, and other technical interviews.
Read more >GitHub - Devinterview-io/api-design-interview-questions
Top 46 API Design interview questions (answered) for developers in 2021 · 1. What REST stands for? · 2. What are the core...
Read more >API Design Interview Preparation - LinkedIn
Tai-Chia (Marcus) Huang · What Are the Goals for API Design for this System? · Define Unit Resources in the System · How...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jacob-ebey Yeah, my original motivation and implementation was also eliminating context, and then eventually I came back to use context which seems to work better in concurrent mode in the future. I also wanted to make use of
observedBits
for performance.Closing this issue. Feel free to open a new one.