1

I'm an Angular and React developper.
I'm trying to use Lightning Web Component in Salesforce Community context for the very first time.

I'm building a multiple step form. The data need to be persisted only at the very end of the form funnel.

  1. How should I handle the form state between steps?
    1.1 Is it possible/recommended to use a state management library like redux or mobx?
    1.2 Should I store it in a parent component using Pubsub events?

Moreover requiring external libraries seems different from regular NPM project.

  1. Can you confirm that it's impossible to add dependencies and include then like this in a Community project:
import _ from 'lodash';

Finally, I want an SPA look and feel

  1. Is it possible to update the url when form steps change?
    3.1. Should I create a page per step and use lightning:navigation ?
    3.2. Can I have a single page and use the router like I'm used to with react

Thank you for you help 😀

0
1

Here are my 2 cents on your question(s):

1.- How should I handle the form state between steps

there are many ways of doing so, using pub/sub events to update the state in components is one way.

if the state is strictly needed in lwc, you should be able to send the state from the children to the parent without using a pub/sub model

I would not recommend using external dependencies if you just need to manage state for a form in communities.

2.- Can you confirm that it's impossible to add dependencies and include then like this in a Community project

You will actually have to import the library from a static resourece as mentioned in Use Third-Party JavaScript Libraries

3.- Is it possible to update the url when form steps change?

3.1 - I would personally NOT create a page per step and keep in in 1 lwc component with children and so on...

3.2 as per routing, you will have to manage differently, check the lwc Navigation documentation

2
  • Thx for your answer ! 👍 Jul 24 '19 at 7:56
  • Unfortunately you confirm my fears: The form is actually only one part of way bigger app. In my experience state management without a great architecture become messy very quickly on large application. I can't imagine using parent/child or pubsub without methodology. I'll have to make my own pattern and hope for this to scale well. Routing looks a bit poor. I would also keep all form step in a single component but I can't find in the router how to virtualize routes. I'm not satisfied with Third-Party javascript libraries import neither. No tree shacking possible and no npm modules Jul 24 '19 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.