catamphetamine / webpack-react-redux-server-side-render-example

A sample React/Redux/Webpack project with Server-Side Rendering

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add property to redux state

TeodorKolev opened this issue · comments

How can I store property childCallerObjectto redux state using that syntax?

export const addUser = redux.action (
	'ADD_USER',
	async ({ http }, user, childCallerObject) =>{
		await delay(1500)
		await http.post(`/api/example/users`, user)
	},{ result: 'users'}
)
const initialState = { users: [] }

I want to get child, from which I call that method and store it in redux. How is that possible with this syntax?

Instead of doing

await addUser(user, childCallerObject)

do

setChildCallerObject(childCallerObject)
await addUser(user)

https://github.com/catamphetamine/react-isomorphic-render#synchronous-actions

This could work:

export const setChildCallerObject = redux.action('ADD_CHILD', {
  result : 'childCallerObject'
})

Why do you @connect() two times.
Do a single connect.

@connect(({ asyncprop, childCallerObject }) => {
  ...properties(asyncprop),
  ...propertiezzzz(ChildCallerObject)
}, {
  getAsyncprop
})
export default class MyClass extends Component {

You are probably not using Babel, or maybe some preset is not enabled, like
https://babeljs.io/docs/plugins/transform-object-rest-spread/

Then the correct code is:

@connect(({ asyncprop, childCallerObject }) => ({
  ...properties(asyncprop),
  ...propertiezzzz(ChildCallerObject)
}), {
  getAsyncprop
})
export default class MyClass extends Component {

Paste how you call it and where

This is not complete code

export const getAutocomplete = redux.on('GET_AUTOCOMPLETE', (state, action) => {
  // this doesn't print anything
  console.log(...state)
  console.log(action)
  return { ...state, cityrow: action.cityrow }
})

https://github.com/catamphetamine/react-isomorphic-render#synchronous-actions

You're using the wrong function

export const getAutocomplete = redux.action('GET_AUTOCOMPLETE', {
  result : 'cityrow'
})

Not sure what exactly do you want to do

It's not a bug.

Which exactly method didn't do what

If it didn't print anything then it means no 'GET_AUTOCOMPLETE' action was dispatched.

redux.on('GET_AUTOCOMPLETE') won't be called because the action() dispatches another event.
Enable Redux devtools to see which events are emitted and there will be the answer to your question.

action dispatches GET_AUTOCOMPLETE and redux.on call GET_AUTOCOMPLETE from redux dev tools

Give me a screenshot proving that

action dispatches GET_AUTOCOMPLETE and redux.on call GET_AUTOCOMPLETE from redux dev tools

Just as I said, your screenshot proves otherwise – it's not GET_AUTOCOMPLETE.

But then you added eventName() function call which could fix that bug in your code.
But by doing that you introduced yet another bug.
Read the example code to see how to use eventName() properly
https://github.com/catamphetamine/react-isomorphic-render#asynchronous-actions

I call GET_CITY

You cannot call GET_CITY because it is a string and one cannot call a string

what can I call in redux.on

Your language is extremely unclear

GET_CITY is an action correct?

Yes.

Read the correct eventName() usage.
You're calling it wrong.
See the link I posted for the correct invocation.

is this the thing that I should read?

Yes.
And you're calling eventName() wrong.
You're not supplying it the correct arguments.