devlinb/react-native-simple-survey

Persist data with Redux

Closed this issue · 4 comments

Hi,

Great component, more than an Issue I have a question. I'm sure that using the callback functions I can save every answer to a redux store and onSurveyFinished I can have the full survey saved on my store. My question is , how can I preload those answers?, in the event that the user answers 50% of the survey, how can I resume the user where it left without having to re-enter the questions he already answer?

many thanks in advance.

Right now the component doesn't support doing this, it is an easy addition to make, add support for pre-populating all fields and not just selectors.

That'd require injecting into the JSON stream which isn't the prettiest solution but the only one inline with how this component otherwise works.

Would that suffice for your needs? It doesn't exactly make redux integration easy, but you're already feeding it JSON from somewhere!

Part of the goal of this component is to be not need to worry about redux until the very end, after the survey is completed. Of course if you want to persist results and come back to the survey later it does become needed.

I should probably add a function that spits out the JSON so far that can be called off of a ref, that'd allow coming back to the survey w/o getting redux involved in transforming a store to/from JSON.

I actually made this entire component because I didn't want to have to integrate dozens of fields into redux, and this component lets me A/B test forms by just changing things up on my backend DB.

Hi devlinb, thanks for your response. The solution to be able to spits out the JSON so far, would be a really good solution for this purpose, that could be stored and presented to the component later if needed.

And one more thing, I realized that i could send and object instead of a string for the Question, this was in order to have different formats on the question (i.e i have a numeric sequense of the questions formated with one color and font, and the actual question with another color and font) and is working fine. However I'm getting a warning that the type of the question expected is a string not and object. Is there a way to have it expect both a string or and object to eliminate this warning?

Again, thanks so much for this component!

Do you mean you are passing an object for questionText in the JSON?

Huh, not a bad idea, now I feel bad that I called that questionText since it can be anything. :)

I've loosened the restrictions on it, the warning should be gone, but I didn't test it, I just changed the PropTypes.

A new version is up now, there are breaking changes after I fixed some of the callbacks.

One thing to be aware of is that the JSON doesn't have the index of the selection option(s) for selection groups, so it isn't a straightforward to restore state. I thought about it and decided that putting the index in the JSON would interfere with the main purpose of the component, which is allowing for going from a JSON backend database to a front end UI and feeding the results right back into the DB.