mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 00:20:28 +01:00
Updates useFormState to allow a sync function to be passed as an action. A form action is almost always async, because it needs to talk to the server. But since we support client-side actions, too, there's no reason we can't allow sync actions, too. I originally chose not to allow them to keep the implementation simpler but it's not really that much more complicated because we already support this for actions passed to startTransition. So now it's consistent: anywhere an action is accepted, a sync client function is a valid input.
30 lines
663 B
JavaScript
30 lines
663 B
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
'use strict';
|
|
|
|
/**
|
|
* turns
|
|
* { 'MUCH ERROR': '0', 'SUCH WRONG': '1' }
|
|
* into
|
|
* { 0: 'MUCH ERROR', 1: 'SUCH WRONG' }
|
|
*/
|
|
function invertObject(targetObj) {
|
|
const result = {};
|
|
const mapKeys = Object.keys(targetObj);
|
|
|
|
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
|
|
for (const originalKey of mapKeys) {
|
|
const originalVal = targetObj[originalKey];
|
|
|
|
result[originalVal] = originalKey;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
module.exports = invertObject;
|