反应-从数组中删除项目而不重新呈现列表

时间:2020-10-07 19:30:28

标签: javascript reactjs typescript rendering use-state

我无法理解为什么此代码无法正常工作。它将状态下的人员数组中的项目删除,但不会重新呈现列表。

// Before running the sample:
 * // - Enable the API at:
 * //   https://console.developers.google.com/apis/api/androidpublisher.googleapis.com
 * // - Login into gcloud by running:
 * //   `$ gcloud auth application-default login`
 * // - Install the npm module by running:
 * //   `$ npm install googleapis`
 *
 * const {google} = require('googleapis');
 * const androidpublisher = google.androidpublisher('v3');
 *
 * async function main() {
 *   const auth = new google.auth.GoogleAuth({
 *     // Scopes can be specified either as an array or as a single, space-delimited string.
 *     scopes: ['https://www.googleapis.com/auth/androidpublisher'],
 *   });
 *
 *   // Acquire an auth client, and bind it to all future calls
 *   const authClient = await auth.getClient();
 *   google.options({auth: authClient});
 *
 *   // Do the magic
 *   const res = await androidpublisher.purchases.subscriptions.get({
 *     // The package name of the application for which this subscription was purchased (for example, 'com.some.thing').
 *     packageName: 'placeholder-value',
 *     // The purchased subscription ID (for example, 'monthly001').
 *     subscriptionId: 'placeholder-value',
 *     // The token provided to the user's device when the subscription was purchased.
 *     token: 'placeholder-value',
 *   });
 *   console.log(res.data);
 *
 *   // Example response
 *   // {
 *   //   "acknowledgementState": 0,
 *   //   "autoRenewing": false,
 *   //   "autoResumeTimeMillis": "my_autoResumeTimeMillis",
 *   //   "cancelReason": 0,
 *   //   "cancelSurveyResult": {},
 *   //   "countryCode": "my_countryCode",
 *   //   "developerPayload": "my_developerPayload",
 *   //   "emailAddress": "my_emailAddress",
 *   //   "expiryTimeMillis": "my_expiryTimeMillis",
 *   //   "externalAccountId": "my_externalAccountId",
 *   //   "familyName": "my_familyName",
 *   //   "givenName": "my_givenName",
 *   //   "introductoryPriceInfo": {},
 *   //   "kind": "my_kind",
 *   //   "linkedPurchaseToken": "my_linkedPurchaseToken",
 *   //   "obfuscatedExternalAccountId": "my_obfuscatedExternalAccountId",
 *   //   "obfuscatedExternalProfileId": "my_obfuscatedExternalProfileId",
 *   //   "orderId": "my_orderId",
 *   //   "paymentState": 0,
 *   //   "priceAmountMicros": "my_priceAmountMicros",
 *   //   "priceChange": {},
 *   //   "priceCurrencyCode": "my_priceCurrencyCode",
 *   //   "profileId": "my_profileId",
 *   //   "profileName": "my_profileName",
 *   //   "promotionCode": "my_promotionCode",
 *   //   "promotionType": 0,
 *   //   "purchaseType": 0,
 *   //   "startTimeMillis": "my_startTimeMillis",
 *   //   "userCancellationTimeMillis": "my_userCancellationTimeMillis"
 *   // }
 * }

我不明白为什么不重新渲染。 我正在StackBlitz上执行此操作,因此您可以在此链接上对其进行测试 https://react-ts-j1kkcp.stackblitz.io

1 个答案:

答案 0 :(得分:0)

您需要解构新列表:setPeople([...aux]);否则React将认为一切都没有改变。